私はそのコードを持っています:
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);
しかし、「これ」はウィンドウを指しており、変更方法がわかりません。