vendredi 24 mars 2017

Ember JS how to implement a normal ES6 class

I'm new to Ember and I'm having an issue with understanding exactly where "reusable" code should go. From what I've found so far, it sounds like this is supposed to be a utility? The only issue I have no idea how to include the class (or any reusable methods) into the controller.

Here's what I'm after

Example class (where would this go?):

'use strict'

class Person{
    constructor(name, age){
        this.name = name;
        this.age = age;
    }

    getPerson(){
        return "My name is " + this.name + " and I'm " + this.age + " years old";
    }
}

/app/routes/index.js:

import Ember from 'ember';
export default Ember.Route.extend({
    beforeModel(){
        this.replaceWith('rentals');
    }
});

/* How would I include the class so I could call the below??
    var person1 = new Person('Bob', '15');
    var person2 = new Person('Kevin', '41');
    console.log(person1.getPerson());
    console.log(person2.getPerson());
*/




Aucun commentaire:

Enregistrer un commentaire