Skip to content

Instantly share code, notes, and snippets.

@js2me
Created October 11, 2017 08:26
Show Gist options
  • Save js2me/6390dfafe537f848c61f7945b8280435 to your computer and use it in GitHub Desktop.
Save js2me/6390dfafe537f848c61f7945b8280435 to your computer and use it in GitHub Desktop.
Basic JavaScript classes extension
if (!Array.prototype.last){ //last element of Array :) If you like to write better .last() then [array.length-1]
Array.prototype.last = function(){
return this[this.length - 1];
};
};
if (!Array.prototype.first){ //similarly, but first element of array [0]
Array.prototype.first = function(){
return this[0];
};
};
if (!Number.prototype.isOne){ //
Array.prototype.isOne = function(){
return this == 1;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment