Javascript Object and Function Object

Source: Internet
Author: User

1. Object

  • Prototype object

A prototype is an attribute of an object, that is, the prototype attribute. Each object has this internal attribute and is also an object.

<Script type = "text/javascript"> Object. prototype. num = 10; alert ("add prototype Object Property:" + Object. num); Object. num = 20; alert ("add Object Property:" + Object. num); </script>

Running result: Add prototype Object Property: 10 Add Object Property: 20

  • Prototype chain
Object. prototype. a = 3.14; alert ("instance of the Object:" + new Object (). a); alert ("attributes of the String object:" + String. a );

Running result: instance of the Object: 3.14 String Object property: 3.14

Analysis: After the Object prototype is extended, the Object is changed to an Object. prototype, that is, all local objects have attributes of this Object. Because all local objects inherit from this Object, String also has the value of attribute.

 

2. Function object

  • Arguments object

When a function is executed, the system automatically creates an arguments object attribute for the function object. The arguments object attribute can only be used in the function body and used to manage the actual parameters of the function.

(1) caller attributes

The caller attribute shows the caller of the function. In the following example, function B () is used to call function a and function B is null;

<script type="text/javascript">    var a = new Function("alert('a:'+a.caller)");    function b()    {      a();      alert('b:'+b.caller);    }    b();</script>

Running effect:

(2) length attribute

Length is the attribute of the arguments object, indicating the number of parameters passed when the function is called. You can access an actual parameter through an array.

function argc(){   alert(arguments[0]+arguments[1]+arguments[3]);}argc(1,2,3);

The running result is 6.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.