AngularJS 1.5 error bootstrap IBM Mobilefirst

前端 未结 3 2114
忘掉有多难
忘掉有多难 2020-12-17 16:41

I seem to have problems combining an MFP hybrid (no cordova) application and angular 1.5. The same application with angular 1.4.9 works fine, but if I switch to angular1.5 t

相关标签:
3条回答
  • 2020-12-17 16:55

    I had the exact same problem when I upgraded to angular 1.5.0.
    The problem turned out to be with a custom implementation of Function.prototype.bind that we had in our code, it looks like this interfered with the one defined in angular.

    Take at the second line on your error callstack

    at new <anonymous> (http://localhost:10080/Hybrid/apps/services/preview/HelloWorld/android/1.0/default/worklight/worklight.js:1033:23)
    

    I think worklight.js may have an implementation of prototype.bind which is incompatible with the one in angular (see https://code.angularjs.org/1.5.0/docs/api/ng/function/angular.bind)

    0 讨论(0)
  • 2020-12-17 17:03

    As others have mentioned, this can be caused by polyfills for Function.prototype.bind. In particular, it seems to be caused by ones that don't properly handle calling the function as a constructor with new. Simple implementations may always return the bound object regardless of invocation, whereas the expectation is that the new operator prevails over the binding and the newly created object gets returned instead.

    eg.

    // create an object to bind to
    var alt = {
        message: 'I am the alternate'
    };
    
    // our function
    function myFunc() { 
       console.log( this.message );
    };
    
    // bind our alternate object to this for myFunc
    myFunc.bind( alt );
    

    Standard Invocation Runs as Expected

    myFunc(); // output 'I am the alternate'
    

    Invocation via new not as Expected (this is the one that breaks angular 1.5)

    new myFunc(); // also outputs 'I am the alternate'</jscodeblock>
    

    The expected behavior is that new invocation will return a new object and not the bound one.

    If you need a polyfill for Function.prototype.bind be sure it properly handles this scenario such as the one found on MDN.

    0 讨论(0)
  • 2020-12-17 17:14

    Also seeing this on the MFP 8.0 cordova plugin.

    0 讨论(0)
提交回复
热议问题