Вопрос

I have a beginner (sorry) question on the element polymer-ajax.

In the file "polymer-ajax.html" (a link), line 249 there is a mysterious binding :

args.callback = this.receive.bind(this);

What is this ? The callback could not work without it ? Why ?

Thanks for your help.

Это было полезно?

Решение

bind is a basic JavaScript built-in that attaches a context to a function. IOW, when args.callback is invoked, the this value will be the this passed to bind. See here:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top