Skip to content

Instantly share code, notes, and snippets.

@LudoBermejo
Created October 4, 2016 15:44
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/eb78431828f7f59dfa44e6745f31068f to your computer and use it in GitHub Desktop.
Save LudoBermejo/eb78431828f7f59dfa44e6745f31068f to your computer and use it in GitHub Desktop.
New Twiddle

EmberJS Classes Example #4

An example of functions.

Please check init. Init is executed when the class is created. Please check that you can change the properties of the class when you create an object based on this class; init function will be executed after that.

import Ember from 'ember';
let consoleTrace = [];
const ForceUserCharacter = Ember.Controller.extend({
name: 'User of the force',
weapon: 'Standard lightsaber',
init() {
consoleTrace.push(`I'm ${this.get('name')} and I have this ${this.get('weapon')}`);
}
})
const forceUserCharacter = ForceUserCharacter.create();
const anakinCharacter = ForceUserCharacter.create({
name: 'Anakin Skywalker',
weapon: 'Blue lightsaber'
});
export default Ember.Controller.extend({
consoleTrace: consoleTrace
});
{
"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