javascript - Function.prototype.bind -


I have found a very interesting question about the Encoder-5 function. Prototype Point implementation generally when you use bind, you do this:

  var myFunction = function () {warnings (this); } .bind (123); // 123 will warn myFunction ();   

OK, that's good, but what do we think when we do this?

  // rebind function myfunction = myfunction.bind ('foobar'); // will warn ... 123! Myfunction ();   

I understand that function. According to Prototype.bind implemented () it is completely logical behavior. But in the real life situation it is not completely useless behavior? The question is: Is this a bug or a feature? If this is a bug, then why is it not anywhere? If this is a feature, then why "chrome" basically treats "bind" implementation exactly the same?

To make it even more clear, what would be more understandable in my opinion, here is the code snippet that applies the function.prototype Slightly left:

  if (! Function.prototype.bind) {function.prototype.bind = function () {var funcObj = this; Var Original = Maccab; Var extraArgs = Array.prototype.slice.call (logic); Var thisObj = extraArgs.shift (); Var func = function () {var thatObj = thisObj; Original return (That obje, extra part.Cockets (array.prototype.lice.call (argument, extragrace.length))); }; Func.bind = function () {var args = Array.prototype.slice.call (argument); Return function.prototypebind.free (funkskob, args); } Return funk; }; }   

Try it now:

  // rebind function myFunction = myFunction.bind ('foobar'); // will warn ... "FOB" myFunction ();   

In my opinion, instead of "this" makes sense ...

So what do you guys think about it?

function.prototype.bind for example in different JS structures The implementation was. For my best knowledge, none of them allow this - after binding, to be changed by the binding. You can also ask why none of them make changes, because it asks why ES5 does not allow it.

You are not the only person I have heard that this is strange. Chris Larry, who works on Mozilla's JS engine (as I did), a few months ago, raising the issue on Twitter was a little strange. And in some different form, I remember one of the Mozilla Labs Hackers who asks if there was any way to "unbind" the function, to remove the target function for it. (If you can do this, you can definitely bind it in a different this , at least if you can pass it to remove the forced logic list.)

I do not remember that when the tie was being specified, this issue is being discussed, however, especially on the e-mailing mailing list, Was not paying attention, when this stuff came out. He said, I do not believe that ES5 was searching for a lot of innovation in the field, making just one phrase "a cowboy" to borrow.

You may possibly propose some self-sufficient methods to address them. If you write adequate detailed proposals then concerns for e-discussion on the other hand, is a form of binding information-hidden mechanism, which It will cut against adoption. It is worth trying to make some proposition, if you have time, I guess the reason for the information-hidden concern will be prevented from adopting the proposal. But this is just an estimate which may well be wrong. The only way to find out ...

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -