我有那个代码:
function defineProperty(object, name, callback){
if(object.prototype){
Object.defineProperty(object.prototype, name, {"get": callback});
}
}
defineProperty(String, "isEmpty", function(){return this.length === 0;});
我使用它如下:
console.log("".isEmpty, "abc".isEmpty);
它返回:
true, false
现在,我想将功能更改为这样的:
defineProperty(String, "isEmptyWithArrow", () => this.length === 0);
但是“this”是指Window,我不知道如何更改它。