So ever once in a while, just for fun, I check out the source of Facebook to find all kinds of crazy javascript.
So in the keyup of the textarea on the facebook chat, i found:
Bootloader.loadComponents(["control-textarea"], function () {
TextAreaControl.getInstance(this)
}.bind(this));
This didn’t seem to interest me until I relized that .bind() is added directly to that function.
I didn’t know you can do that.
Can any function be after to another function(){} just like that? Or is there a special way you need to do this.
I know you can chain stuff like "How are you doing!".replace(/\w{3}/g,'').toUpperCase(), but didn’t think you chain directly to the function(){} itself.
.bindis a property available on Function objects in ES5 environments, or where.bindhas been added toFunction.prototype. It’s just like any other property available on an object or via the prototype chain.The
.bindmethod returns a new function with its calling context (and arguments if provided) permanently bound to that new function. The new function invokes the code body of the original function, so aside from the bound context and args, the behavior is otherwise the same.