I looked around for how to use the Object.defineProperty method, but couldn\'t find anything decent.
Someone gave me this snippet of code:
Object.def
Object.defineProperty(Array.prototype, "last", { get: function() { if (this[this.length -1] == undefined) { return [] } else { return this[this.length -1] } } }); console.log([1,2,3,4].last) //returns 4