javascript Custom function for array

Viewed 36

Can someone explain why this works:

Object.defineProperty(Array.prototype, 'getRandom', {
    value: function(){return this[randomInt(0, this.length)]}
})

But why this doesn't works?

Object.defineProperty(Array.prototype, 'getRandom', {
    value: () => this[randomInt(0, this.length)]
})
0 Answers
Related