📜  Prototype-基本对象

📅  最后修改于: 2020-10-21 08:45:36             🧑  作者: Mango


 

Prototype将Object用作对象的名称空间,并使用Object对象调用相关函数。通过以下两种方式使用它-

  • 如果您是一个简单的开发人员,则可以使用现有功能,例如inspectclone
  • 如果您希望像Prototype一样创建自己的对象,或者像散列一样探索对象,则将扩展extendkeyvalues

Prototype对象方法

注意-确保至少具有1.6版的prototype.js。

S.No. Method & Description
1. clone()

Clones the passed object using shallow copy (copies all the original’s properties to the result).

2. extend()

Copies all properties from the source to the destination object.

3. inspect()

Returns the debug-oriented string representation of the object.

4. isArray ()

Returns true if obj is an array, false otherwise.

5. isElement()

Returns true if obj is a DOM node of type 1, false otherwise.

6. isFunction()

Returns true if obj is of type function, false otherwise.

7. isHash()

Returns true if obj is an instance of the Hash class, false otherwise.

8. isNumber()

Returns true if obj is of type number, false otherwise.

9. isString()

Returns true if obj is of type string, false otherwise.

10. isUndefined()

Returns true if obj is of type undefined, false otherwise.

11. keys()

Treats any object as a Hash and fetches the list of its property names.

12. toHTML()

Returns the return value of obj’s toHTML method if it exists, else runs obj through String.interpret.

13. toJSON()

Returns a JSON string.

14. toQueryString()

Turns an object into its URL-encoded query string representation.

15. values()

Treats any object as a Hash and fetches the list of its property values.