1 (function (window) {
var core_arrpro = Array.prototype;
3 var core_slice = Core_arrpro.slice;
4 var core_push = Core_arrpro.push;
5 var core_unshift = Core_arrpro.unshift;
6
7 function StringBuffer () {
8 this.buffer = [];
9}
Ten Stringbuffer.prototype = {
One push:function () {
Core_push.apply (This.buffer, Core_slice.call (arguments));
return this;
14},
Unshift:function () {
Core_unshift.apply (This.buffer, Core_slice.call (arguments));
return to this;
18},
Tostring:function () {
return This.buffer.join (');
21}
22};
return window. StringBuffer = StringBuffer;
) (window);
document.getElementById (' result '). InnerHTML = new StringBuffer (). push (' ASDASD '). Unshift (' 654 ', 123). Push (123, 564 , ' SDF ');
Because the apply efficiency is lower than call, and most push operations have only 1 parameters, the update is as follows:
(function (window) {
var core_arrpro = Array.prototype;
var core_slice = Core_arrpro.slice;
function StringBuffer () {
This.buffer = [];
}
Stringbuffer.prototype = {
Push:function () {
if (arguments.length = = 1) {
This.buffer.push (Arguments[0])
}else if (Arguments.length > 1) {
This.buffer = This.buffer.concat (core_slice.call (arguments));
}
return this;
},
Unshift:function () {
if (arguments.length = = 1) {
This.buffer.unshift (Arguments[0])
}else if (Arguments.length > 1) {
This.buffer = core_slice.call (arguments). Concat (This.buffer)
}
return this;
},
Tostring:function () {
Return This.buffer.join (");
}
};
return window. StringBuffer = StringBuffer;
}) (window);
document.getElementById (' result '). InnerHTML = New StringBuffer (). push (' ASDASD '). Unshift (' 654 ', 123). Push (123, 564, ' SDF ');