Prototype extensions

To make your life simpler, Ember.js framework extends the prototypes of Array, String, Function are native JavaScript objects. These extensions provide you with simpler ways of accessing and manipulating these native objects.

As for arrays, you could do the following:

export default function(){
  console.log([1,2,3].get('lastObject')); //4

  var arr = [1,2,3,4,5,6,7].filter(function(item){
    if(item < 5){
      return true;
    }
  });
  console.log(arr);//[1,2,3,4]
}

The contents of prototype.js are present in chapter-2/example10/app/prototype.js

For strings, you could do the following:

console.log("ember.js".capitalize()); //Ember.js
console.log("my var".camelize());//myVar
console.log("my var".classify());//MyVar

Note

For a complete list of Array helper methods, please refer to the API documentation, found at http://emberjs.com/api/classes/Ember.Array.html.

Similarly, for String helper please see the API documentation, found at http://emberjs.com/api/classes/Ember.String.html.

These function prototype extensions will help you to use getters, setters, computed properties, observers, and much more. Examples of computed properties, bindings, and observers fit well here.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.245.167