Skip to content

Instantly share code, notes, and snippets.

@LudoBermejo
Last active October 11, 2016 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LudoBermejo/fdb53810d445c8cc98939696795869c6 to your computer and use it in GitHub Desktop.
Save LudoBermejo/fdb53810d445c8cc98939696795869c6 to your computer and use it in GitHub Desktop.
New Twiddle

EmberJS Classes Example #

An example of class extension

You can extend an EmberJS class after it's creation by using the "reopen" function.

Beware! If you create an object and then reopen the class, the object will not have the property! You can check the "moreDetails" property to know that.

More... you can create static properties to the class by using reopenClass. You can always overwrite that by creating an object.

I know, it's complicated and possibly you will never use it... but still, it's here, in the code.

import Ember from 'ember';
let SkyWalkerFamily = Ember.Object.extend({
surname: "Skywalker"
});
SkyWalkerFamily.reopen( {
details: "Force is strong in him"
});
SkyWalkerFamily.reopenClass( {
lastJedi: "Luke"
});
SkyWalkerFamily.reopen( {
lastJedi: "Ben"
});
let luke = SkyWalkerFamily.create( {
name: "Luke"
});
SkyWalkerFamily.reopen( {
moreDetails: "They usually ends killing each other"
});
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
skyWalkerMember: luke,
SkyWalkerFamily: SkyWalkerFamily
});
<h1>{{skyWalkerMember.name}} {{skyWalkerMember.surname}}</h1>
<h2>{{skyWalkerMember.details}}</h2>
<h2>{{skyWalkerMember.moreDetails}}</h2>
<h2>The last Jedi until last movies {{SkyWalkerFamily.lastJedi}}</h2>
<h2>The last Jedi now {{skyWalkerMember.lastJedi}}</h2>
{
"version": "0.10.5",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.8.0",
"ember-data": "2.8.0",
"ember-template-compiler": "2.8.0",
"ember-testing": "2.8.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment