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.

Extending from native classes

See original GitHub issue

Follow up of https://github.com/ember-decorators/ember-decorators/issues/115#issuecomment-427057102 and new issue here, as requested by @rwjblue

Extending a native class with .extend which itself is extending EmberObject is throwing a

TypeError: Class constructor CLASS_NAME cannot be invoked without 'new'

The motivation of this is being able to use native classes and mixins, like this:

class Foo extends EmberObject {
  // ...
}

const Bar = Foo.extend({
  // ...
});

class Baz extends Bar {
  // ...
}

See this ember-twiddle: https://canary.ember-twiddle.com/b365ecfbc29444455d082cf1b295156b?openFiles=tests.foo-test.js%2C

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:19 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
krisseldencommented, Dec 6, 2018

If you create a patched version extend in your app so that babel compiles it according to your App settings.

import EmberObject from "@ember/object";
EmberObject.extend = function (...args) {
  class Class extends this;
  Class.reopen(...args);
  return Class;
}
export default EmberObject;

then import from that in your app it should workaround the problem until we publish the es so that ember-cli compiles ember with the same babel settings.

1reaction
Krzyrokcommented, Apr 17, 2019

Great! Thanks for link 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extend those Native Classes! - Medium
We can extend native classes to get more out of them. ... Overriding & extending native classes to reap more usability through retroactive...
Read more >
Extending built-in classes - The Modern JavaScript Tutorial
As we already know, native classes extend each other. For instance, Array extends Object . Normally, when one class extends another, ...
Read more >
Native Classes - Octane Upgrade Guide - Ember Guides
Use the create static method to create instances of the class: const Person = EmberObject.extend({}); let jen = Person. · You can pass...
Read more >
Missing extension of native class? - Unity Answers
[System.Serializable] public class Dialogues { public string speakerName; public Animator anim;. [TextArea( ...
Read more >
Extending Classes And Interfaces - NativeScript Docs
The main difference between inheriting classes and implementing interfaces in NativeScript is the use of the extend keyword. Basically, you implement an ...
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