Prototype JavaScript framework

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.

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.

    undefined and null are represented as such.

    Other types are checked for a inspect method. If there is one, it is used; otherwise, it reverts to the toString method.

    Prototype provides inspect methods for many types, both built-in and library-defined — among them String, Array, Enumerable and Hash. 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 true if object is an array; false otherwise.

  • isElement

    Object.isElement(object) -> Boolean
    • object (Object) – The object to test.

    Returns true if object is a DOM node of type 1; false otherwise.

  • isFunction

    Object.isFunction(object) -> Boolean
    • object (Object) – The object to test.

    Returns true if object is of type function; false otherwise.

  • isHash

    Object.isHash(object) -> Boolean
    • object (Object) – The object to test.

    Returns true if object is an instance of the Hash class; false otherwise.

  • isNumber

    Object.isNumber(object) -> Boolean
    • object (Object) – The object to test.

    Returns true if object is of type number; false otherwise.

  • isString

    Object.isString(object) -> Boolean
    • object (Object) – The object to test.

    Returns true if object is of type string; false otherwise.

  • isUndefined

    Object.isUndefined(object) -> Boolean
    • object (Object) – The object to test.

    Returns true if object is of type string; false otherwise.

  • 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…in loop, 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’s toHTML method if it exists; else runs object through String.interpret.

  • toJSON

    Object.toJSON(object) -> String
    • object (Object) – The object to be serialized.

    Returns a JSON string.

    undefined and function types have no JSON representation. boolean and null are coerced to strings.

    For other types, Object.toJSON looks for a toJSON method on object. If there is one, it is used; otherwise the object is treated like a generic Object.

  • toQueryString

    Object.toQueryString(object) -> String

    object (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 encodeURIComponent function.

    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…in loop, 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.