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

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

Description

@EisenbergEffect

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;
        }
    });
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions