zloirock / core-js

Standard Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Should the implementation of the bind polyfill check for new invocation before assigning the prototype?

manyuemeiquqi opened this issue · comments

When view bind polyfill, i think this line code should judge.
e.g.

function log1(){
  console.log(this.name)
}
log1.prototype.funcName = 'log1'

console.log(log1.prototype.funcName)

var log2 = log1.bind(null)

console.log(log2.prototype)


var o = new log1()
console.log(o.__proto__.funcName)

The polyfill current will cause bindFunction has prototye whenever.

In ES3 is impossible to make a completely correct Function.prototype.bind polyfill.

The spec requires that the result hasn't a .prototype property at all - but it can't be removed from usual functions; IIRC in some engines it can be only an object.

Also, should work

function F() { /* empty */ }
var B = F.bind();
new F() instanceof B; // should be true

and some other such moments.

So the current approach is not completely correct by the spec, but I don't see a way how to do it better.