Ember.js常用函数

While developing stuff with Ember.js I stumbled upon some very nice and handy functions which are built in. This post lists some of them and describes in a short what they are used for.
当用Ember.js开发时,我发现了一些优美且实用的函数。本文列出了它们,并简短地说明了用法。

The following functions are defined in packages/ember-runtime/lib/core.js and packages/ember-metal/lib/utils.js respectively.

Returns true if argument is null or undefined.

nonenone
1
2
3
4
5
6
Ember.none(); // true
Ember.none(null); // true
Ember.none(undefined); // true
Ember.none(''); // false
Ember.none([]); // false
Ember.none(function(){}); // false

This utility function constrains the rules on Ember.none by returning false for empty string and empty arrays.

empty
1
2
3
4
5
6
7
Ember.empty(); // true
Ember.empty(null); // true
Ember.empty(undefined); // true
Ember.empty(''); // true
Ember.empty([]); // true
Ember.empty('tobias fünke'); // false
Ember.empty([0,1,2]); // false

Use this to check if a value is an array. This method also returns true for array-like objects, like the ones implementing Ember.Array.

Array
1
2
3
Ember.isArray(); // false
Ember.isArray([]); // true
Ember.isArray( Ember.ArrayProxy.create({ content: [] }) ); // true

More useful String functions

There are some more functionalities for converting between different String notations: camelize(), decamelize(), dasherize(), underscore()

Posted by Clemens Müller Mar 8th, 2012
Ember.js

http://code418.com/blog/2012/03/08/useful-emberjs-functions/](http://code418.com/blog/2012/03/08/useful-emberjs-functions/


觉得本文有帮助,长按二维码进行微信打赏