get and set

At the core of Ember Data’s model records is an Ember.Object. This object definition contains the methods get and set. Unlike most languages, JavaScript does not force the use of getters and setters on object instances. Ember applies the concepts of getters and setters with these methods to force a function to be run when changing an object property. This allows Ember to add event triggers to set and make programmers be intentional when getting properties.

The get method takes a single argument, the property name, to retrieve the property value. Try it out in the app/routes/sightings.js model callback.

import Ember from 'ember'; export default Ember.Route.extend({ model() { let record1 = this.store.createRecord('sighting', ...

Get Front-End Web Development: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.