Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

bug(providers): methodless class instantiation broken in IE #69

Open
EisenbergEffect opened this issue Sep 11, 2014 · 0 comments
Open
Labels

Comments

@EisenbergEffect
Copy link

This is an IE-only bug.

If you have a class, which has a constructor, but nothing on the prototype, then the FactoryProvider will be used instead of the ClassProvider. This causes this to be undefined in the constructor of the class during instantiation, which usually results in exceptions.

The name property of function is non-standard and not implemented in any version of IE up to now (11). However, you can polyfill name. See this stack overflow discussion for a simple implementation which appears to fix these issues, at least in my tests: http://stackoverflow.com/questions/6903762/function-name-not-supported-in-ie

Providing the polyfill inline here for convenience:

// Fix Function#name on browsers that do not support it (IE):
if (!(function f() {}).name) {
    Object.defineProperty(Function.prototype, 'name', {
        get: function() {
            var name = this.toString().match(/^\s*function\s*(\S*)\s*\(/)[1];
            // For better performance only parse once, and then cache the
            // result through a new accessor for repeated access.
            Object.defineProperty(this, 'name', { value: name });
            return name;
        }
    });
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant