question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

It seems there is a conflict with prototype.js.

This method line return new (_bind.apply(Class, [null].concat(args)))(); fails because it is using the bind method of prototype

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
vvocommented, Sep 21, 2015

For reference, prototype.js:

  1. overwrite .bind in < 1.7.2.
  2. does a bad job with the polyfill (not forwarding .prototype etc).

You can just insert this:

// Magento is using a very old prototype.js version with a poor Function.prototype.bind
// forced overloading, we redefine it here so that our code works
// ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
Function.prototype.bind = function(oThis) {
  if (typeof this !== 'function') {
    // closest thing possible to the ECMAScript 5
    // internal IsCallable function
    throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
  }

  var aArgs   = Array.prototype.slice.call(arguments, 1),
      fToBind = this,
      fNOP    = function() {},
      fBound  = function() {
        return fToBind.apply(this instanceof fNOP
               ? this
               : oThis,
               aArgs.concat(Array.prototype.slice.call(arguments)));
      };

  if (this.prototype) {
    // native functions don't have a prototype
    fNOP.prototype = this.prototype;
  }
  fBound.prototype = new fNOP();

  return fBound;
};

Before inserting instantsearch.js

0reactions
redoxcommented, Sep 21, 2015

So Prototype.js (< 1.7.2) actually replaces the bind method in every cases: https://github.com/sstephenson/prototype/commit/9559d8892d9edb8bdf53391c11dfa32bdaf6bf39

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prototype JavaScript framework: a foundation for ambitious ...
Advanced JavaScript made simple. Prototype is an open-source JavaScript framework that smooths over the rough edges of cross-browser development so you can ...
Read more >
JavaScript Object Prototypes - W3Schools
All JavaScript objects inherit properties and methods from a prototype: ... The Object.prototype is on the top of the prototype inheritance chain: Date...
Read more >
Object prototypes - Learn web development | MDN
Prototypes are the mechanism by which JavaScript objects inherit features from one another. In this article, we explain what a prototype is, ...
Read more >
Prototype in JavaScript - TutorialsTeacher
The prototype is an object that is associated with every functions and objects by default in JavaScript, where function's prototype property is accessible ......
Read more >
JavaScript Prototype (with Examples) - Programiz
In JavaScript, every function and object has a property named prototype by default. For example,. function Person () { this.name = ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found