class Object
Description
Extensions to the built-in Object object.
Because it is dangerous and invasive to augment Object.prototype (i.e.,
add instance methods to objects), all these methods are static methods that
take an Object as their first parameter.
Methods
Class methods
-
clone
Object.clone(object) -> Object-
object(Object) – The object to clone.
Duplicates the passed object.
Copies all the original's key/value pairs onto an empty object.
Do note that this is a shallow copy, not a deep copy. Nested objects will retain their references.
-
-
extend
Object.extend(destination, source) -> Object-
destination(Object) – The object to receive the new properties. -
source(Object) – The object whose properties will be duplicated.
Copies all properties from the source to the destination object. Returns the destination object.
-
-
inspect
Object.inspect(object) -> String-
object(Object) – The item to be inspected.
Returns the debug-oriented string representation of the object.
undefinedandnullare represented as such.Other types are checked for a
inspectmethod. If there is one, it is used; otherwise, it reverts to thetoStringmethod.Prototype provides
inspectmethods for many types, both built-in and library-defined — among themString,Array,EnumerableandHash. These attempt to provide useful string representations (from a developer’s standpoint) for their respective types. -
-
isArray
Object.isArray(object) -> Boolean-
object(Object) – The object to test.
Returns
trueifobjectis an array; false otherwise. -
-
isElement
Object.isElement(object) -> Boolean-
object(Object) – The object to test.
Returns
trueifobjectis a DOM node of type 1;falseotherwise. -
-
isFunction
Object.isFunction(object) -> Boolean-
object(Object) – The object to test.
Returns
trueifobjectis of typefunction;falseotherwise. -
-
isHash
Object.isHash(object) -> Boolean-
object(Object) – The object to test.
Returns
trueifobjectis an instance of theHashclass;falseotherwise. -
-
isNumber
Object.isNumber(object) -> Boolean-
object(Object) – The object to test.
Returns
trueifobjectis of typenumber;falseotherwise. -
-
isString
Object.isString(object) -> Boolean-
object(Object) – The object to test.
Returns
trueifobjectis of typestring;falseotherwise. -
-
isUndefined
Object.isUndefined(object) -> Boolean-
object(Object) – The object to test.
Returns
trueifobjectis of typestring;falseotherwise. -
-
keys
Object.keys(object) -> Array-
object(Object) – The object to pull keys from.
Returns an array of the object's property names.
Note that the order of the resulting array is browser-dependent — it relies on the
for…inloop, for which the ECMAScript spec does not prescribe an enumeration order. Sort the resulting array if you wish to normalize the order of the object keys. -
-
toHTML
Object.toHTML(object) -> String-
object(Object) – The object to convert to HTML.
Converts the object to its HTML representation.
Returns the return value of
object’stoHTMLmethod if it exists; else runsobjectthroughString.interpret. -
-
toJSON
Object.toJSON(object) -> String-
object(Object) – The object to be serialized.
Returns a JSON string.
undefinedandfunctiontypes have no JSON representation.booleanandnullare coerced to strings.For other types,
Object.toJSONlooks for atoJSONmethod onobject. If there is one, it is used; otherwise the object is treated like a genericObject. -
-
toQueryString
Object.toQueryString(object) -> Stringobject (Object): The object whose property/value pairs will be converted.
Turns an object into its URL-encoded query string representation.
This is a form of serialization, and is mostly useful to provide complex parameter sets for stuff such as objects in the Ajax namespace (e.g.
Ajax.Request).Undefined-value pairs will be serialized as if empty-valued. Array-valued pairs will get serialized with one name/value pair per array element. All values get URI-encoded using JavaScript’s native
encodeURIComponentfunction.The order of pairs in the serialized form is not guaranteed (and mostly irrelevant anyway) — except for array-based parts, which are serialized in array order.
-
values
Object.values(object) -> Array-
object(Object) – The object to pull values from.
Returns an array of the object's values.
Note that the order of the resulting array is browser-dependent — it relies on the
for…inloop, for which the ECMAScript spec does not prescribe an enumeration order.Also, remember that while property names are unique, property values have no such constraint.
-
