-
Notifications
You must be signed in to change notification settings - Fork 27
Core
DanilaMihailov edited this page Jun 29, 2012
·
1 revision
Checks if fn is function
if (atom.core.isFunction(object.method)) {
object.method();
}
If key is not object - returns object, where key is single key & value is value of this key.
Else - returns key
atom.core.objectize( 'test', 'foo' ); // { test: 'foo' )
atom.core.objectize({ test: 'foo' }); // { test: 'foo' )
Can be used, when you what to be sure, you works with object:
method: function (callback, nameOrHash, value) {
var hash = atom.core.objectize(nameOrHash, value);
for (var i in hash) {
// do
}
}
Checks is array contains value. Is similar to array.indexOf(value) != -1
if (atom.core.contains(['first', 'second'], value)) {
// do smth
}
Push value to array if it doesn't contains it;
atom.core.includeUnique( [1,2,3], 1 ); // [1,2,3 ]
atom.core.includeUnique( [1,2,3], 4 ); // [1,2,3,4]
Erase first value from array
atom.core.eraseOne( [1,2,3,2,1], 2 ); // [1,3,2,1]
Erase all value from array
atom.core.eraseAll( [1,2,3,2,1], 2 ); // [1,3,1]
Cast arrayLikeObject (array, DomCollection, arguments) to Array
var args = atom.core.toArray(arguments);
Checks if object is arrayLike
if (atom.core.isArrayLike(object)) {
for (var i = 0; i < object.length; i++) {
// do
}
}
Append all properties from sourceto target
var target = { a: 1 };
var source = { b: 2 };
atom.core.append( target, source );
console.log(target); // { a: 1, b: 2 }
Browsers, which do not have JavaScript 1.8.5 compatibility, will get those methods implemented:
get source.