我想向对象Array
添加一个属性。我一直在尝试以下方法:
Array.prototype.isEmpty = array => (array || []).length <= 0 // only works if I use array.isEmpty(array) which isn't exactly what I want.
Array.prototype.isEmpty = (() => (this || []).length <= 0)() // always returns true since this is always undefined.
有没有办法在JavaScript中添加它?