A collection of Object functions.
Used to iterate through an object.
Object.each(obj, fn[, bind]);
fn(item, key, object)
// alerts 'The first day of the week is Sunday', 'The second day of the week is Monday', etc.: Object.each({first: 'Sunday', second: 'Monday', third: 'Tuesday'}, function(value, key){ alert('The ' + key + ' day of the week is ' + value); });
This method is an object-specific equivalent of $each from MooTools 1.2.
Merges any number of objects recursively without referencing them or their sub-objects.
var merged = Object.merge(obj1, obj2[, obj3[, ...]]);
var obj1 = {a: 0, b: 1}; var obj2 = {c: 2, d: 3}; var obj3 = {a: 4, d: 5}; var merged = Object.merge(obj1, obj2, obj3); // returns {a: 4, b: 1, c: 2, d: 5}, (obj2, and obj3 are unaltered) merged === obj1; // true, obj1 gets altered and returned as merged object var nestedObj1 = {a: {b: 1, c: 1}}; var nestedObj2 = {a: {b: 2}}; var nested = Object.merge(nestedObj1, nestedObj2); // returns: {a: {b: 2, c: 1}}
Returns a copy of an object.
var clone = Object.clone(obj);
var obj1 = {a: 0, b: 1}; var obj2 = Object.clone(obj1); obj1.a = 42; alert(obj1.a); // alerts '42' alert(obj2.a); // alerts '0'
This is an object-specific equivalent of $unlink from MooTools 1.2.
Copies all the properties from the second object passed in to the first object passed in.
Object.append(original, extension);
var firstObj = { name: 'John', lastName: 'Doe' }; var secondObj = { age: '20', sex: 'male', lastName: 'Dorian' }; Object.append(firstObj, secondObj); //firstObj is now: {name: 'John', lastName: 'Dorian', age: '20', sex: 'male'};
This method is an object-specific equivalent of $extend from MooTools 1.2.
Get a subset of an object.
Object.subset(object, keys);
var object = { a: 'one', b: 'two', c: 'three' }; Object.subset(object, ['a', 'c']); // returns {a: 'one', c: 'three'}
Creates a new map with the results of calling a provided function on every value in the map.
var mappedObject = Object.map(object, fn[, bind]);
fn(value, key, object)
var myObject = {a: 1, b: 2, c: 3}; var timesTwo = Object.map(myObject, function(value, key){ return value * 2; }); // timesTwo now holds an object containing: {a: 2, b: 4, c: 6};
Creates a new object with all of the elements of the object for which the provided filtering function returns true.
var filteredObject = Object.filter(object, fn[, bind]);
fn(value, key, object)
var myObject = {a: 10, b: 20, c: 30}; var biggerThanTwenty = Object.filter(myObject, function(value, key){ return value > 20; }); // biggerThanTwenty now holds an object containing: {c: 30}
Returns true if every value in the object satisfies the provided testing function.
var allPassed = Object.every(object, fn[, bind]);
fn(value, key, object)
var myObject = {a: 10, b: 4, c: 25, d: 100}; var areAllBigEnough = Object.every(myObject, function(value, key){ return value > 20; }); // areAllBigEnough = false
Returns true if at least one value in the object satisfies the provided testing function.
var anyPassed = Object.some(object, fn[, bind]);
fn(value, key, object)
var myObject = {a: 10, b: 4, c: 25, d: 100}; var areAnyBigEnough = Object.some(myObject, function(value, key){ return value > 20; }); //isAnyBigEnough = true
Returns an array containing all the keys, in the same order as the values returned by Object:values.
var keys = Object.keys(object);
Returns an array containing all the values, in the same order as the keys returned by Object:keys.
var values = Object.values(object);
Returns the number of keys in the object.
var length = Object.getLength(object);
var myObject = { name: 'John', lastName: 'Doe' }); Object.getLength(myObject); // returns 2
Returns the key of the specified value. Synonymous with Array:indexOf.
var key = Object.keyOf(object, item);
var myObject = {a: 'one', b: 'two', c: 3}; Object.keyOf(myObject, 'two'); // returns 'b' Object.keyOf(myObject, 3); // returns 'c' Object.keyOf(myObject, 'four'); // returns false
Tests for the presence of a specified value in the object.
var inObject = Object.contains(object, value);
var myObject = {a: 'one', b: 'two', c: 'three'}; Object.contains(myObject, 'one'); // returns true Object.contains(myObject, 'four'); // returns false
Generates a query string from key/value pairs in an object and URI encodes the values.
var queryString = Object.toQueryString(object[, base]);
Object.toQueryString({apple: 'red', lemon: 'yellow'}); // returns 'apple=red&lemon=yellow' Object.toQueryString({apple: 'red', lemon: 'yellow'}, 'fruits'); // returns 'fruits[apple]=red&fruits[lemon]=yellow'
Hash has been deprecated. Each Hash method has a similar Object method or a Vanilla JS equivalent.
You could simply use myObject.myKey != undefined
Use Object.keyOf
Use Object.contains
Use Object.append
Use Object.merge
Use delete myObject.a
Use myObject.myKey
Use myObject.myKey = value
Use myObject = {}
Use if(myObject.myKey == undefined) myObject.myKey = value
Use Object.map
Use Object.filter
Use Object.every
Use Object.some
Use Object.keys
Use Object.values
© Linux.ria.ua, 2008-2024 |