0
var a = {"b": {"c": function() {console.log(this);}}};
var x = {"b": "I should be 'this'"};
a.b.c();
var a = {"b": {"c": function() {console.log(this);}}};
var x = {"b": "I should be 'this'"};
a.b.c();
このオブジェクトをバインドするか、このオブジェクトとしてプロパティを取得できます。
文字列に変換しなくても、あなたはこのコンソールでオブジェクトのような配列を取得します。
方法:
The
bind()
method creates a new function that, when called, has itsthis
keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.
The
call()
method calls a function with a giventhis
value and arguments provided individually.
マベは、あなたも、ここを見て:this
。
var a = { b: { c: function() { console.log(this.toString()); } } },
x = { b: "I should be 'this'"};
a.b.c.bind(x.b)();
a.b.c.call(x.b);
あなたはこれまでに何をしようとしたのですか? – JohnPan
@Vucko、あなたの編集について、セミコロンは必須ではありませんが、間違っているわけではないので、投稿に残すべきだと思います。 –
@FedericoklezCullocaそれは 'キャッチされないでSyntaxErrorを返します:予期しないトークンを;' – Vucko