GithubHelp home page GithubHelp logo

Comments (6)

jonathantneal avatar jonathantneal commented on May 9, 2024

After testing native bind against our polyfill and the MDN polyfill, I’m afraid I can’t replicate the issue you are having.

Native:
new (String.bind('test')) === new (String.bind('test')) // returns false

Our polyfill:
new (String.bind('test')) === new (String.bind('test')) // returns false

MDN Polyfill:
new (String.bind('test')) === new (String.bind('test')) // returns false

Native:
new (function (e) { console.log(e) }.bind(null, 'test')) // logs "test", returns Object {}

Our polyfill:
new (function (e) { console.log(e) }.bind(null, 'test')) // logs "test", returns bound {}

MDN Polyfill:
new (function (e) { console.log(e) }.bind(null, 'test')) // logs "test", returns fBound {}

Would you provide more details and perhaps a test?

from polyfill-service.

jdalton avatar jdalton commented on May 9, 2024

Your bind will also error when attempting to bind a native method. This is because native methods don't have a prototype property so your bound function gets a prototype of undefined which then throws an error when you do the this instanceof Constructor check.

from polyfill-service.

abozhilov avatar abozhilov commented on May 9, 2024

Sorry about my examples. As I told you built-in constructors have overloaded behavior depends how they are called .

new String('test'); //string object
String('test'); //primitive string value

Your bind implementation doesn't handle that.

String(new (String.bind(null, 'test'))); //Native bind returns 'test'

Your bind fails with error since String#toString is not generic.

from polyfill-service.

matthewwithanm avatar matthewwithanm commented on May 9, 2024

I just bumped into the issue described by @jdalton. Here's the exact message for reference:

Uncaught TypeError: Function has non-object prototype 'undefined' in instanceof check 

And here's code to cause it:

RegExp.prototype.test.bind(/a/)('a');

from polyfill-service.

samgiles avatar samgiles commented on May 9, 2024

Added test case in https://github.com/Financial-Times/polyfill-service/blob/functionbind_test/polyfills/Function.prototype.bind/tests.js

from polyfill-service.

triblondon avatar triblondon commented on May 9, 2024

Lots of issues reported with our bind implementation: ref #313 and #261

from polyfill-service.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.