我有这段代码:
现在,我想把函数更改为以下内容:
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,我不知道如何改变它。