Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance: use Object.setPrototypeOf firstly, then fallback to __proto__ in straightway #4

Open
imcuttle opened this issue Sep 26, 2018 · 0 comments · May be fixed by #5
Open

Performance: use Object.setPrototypeOf firstly, then fallback to __proto__ in straightway #4

imcuttle opened this issue Sep 26, 2018 · 0 comments · May be fixed by #5

Comments

@imcuttle
Copy link

Factory.__proto__ = Class

The above code should be works on inherit Class static properties.

Babel treats the inheritance in ES2015 as follow:

function _inherits(subClass, superClass) {
  if (typeof superClass !== 'function' && superClass !== null) {
    throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass)
  }
  subClass.prototype = Object.create(superClass && superClass.prototype, {
    constructor: {
      value: subClass,
      enumerable: false,
      writable: true,
      configurable: true
    }
  })
  // inherit `Class` static properties
  if (superClass)
    Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : (subClass.__proto__ = superClass)
}

So, the below code should be more robuster.

- Factory.__proto__ = Class 
+ Object.setPrototypeOf ? Object.setPrototypeOf(Factory, Class) : (Factory.__proto__ = Class)
imcuttle added a commit to imcuttle/to-factory that referenced this issue Sep 26, 2018
use `Object.setPrototypeOf` firstly, then fallback to `__proto__` in straightway

close timoxley#4
@imcuttle imcuttle linked a pull request Sep 26, 2018 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant