Skip to content

Instantly share code, notes, and snippets.

@watagashi
Created June 23, 2011 15:02
Show Gist options
  • Save watagashi/1042697 to your computer and use it in GitHub Desktop.
Save watagashi/1042697 to your computer and use it in GitHub Desktop.
var a = ['a', 'b', 'c'];
var b = ['x', 'y', 'z'];
var c = a.concdat(b,true);
a.push('d');
var c = a.join('');
var a = ['a', 'b', 'c'];
var c = a.pop();
var a = ['a', 'b', 'c'];
var b = ['x', 'y', 'z'];
var c = a.push(b,true);
Function.prototype.method = function (name, func) {
if (!this.prototype[name]) {
this.prototype[name] = func;
return this;
}
};
Array.method('push2', function() {
this.splice.apply(
this,
[this.length, 0].concat(Array.prototype.slice.apply(arguments)));
return this.length;
});
var a = ['a', 'b', 'c'];
var b = ['x', 'y', 'z'];
var c = a.push2(b,true);
Array.method('push3', function() {
this.splice.apply(
this,
[this.length].concat(Array.prototype.slice.apply(arguments)));
return this.length;
});
var a = ['a', 'b', 'c'];
var b = ['x', 'y', 'z'];
var c = a.push2(b,true);
var a = ['a', 'b', 'c'];
var b = a.reverse();
var a = ['a', 'b', 'c'];
var c = a.shift();
var a = ['a', 'b', 'c'];
var b = a.slice(0, 1);
var c = a.slice(1);
var d = a.slice(1, 2);
var e = a.slice(0);
var a = ['a', 'b', 'c'];
var r = a.splice(1, 1, 'ache', 'bug');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment