On _javascript skills of object and function objects in JavaScript

Source: Internet
Author: User

1.Object objects

Prototype Object
A prototype is an attribute of an object, which is the prototype attribute, and each object has this intrinsic property, and he is an object in itself.

<script type= "Text/javascript" >
   object.prototype.num=;
   Alert ("Add a Prototype Object attribute:" + object.num);
   Object.num =;
   Alert ("Add object attribute:" +object.num);
</script>

Prototype chain

Object.prototype.a = 3.14;
Alert ("Instance of object:" + New Object (). a);
Alert ("Properties of String object:" + string.a);


Analysis: When the object's prototype is extended, it is the equivalent of objects. Prototype, which means that all local objects have properties of this object, because all local objects inherit from the object, so string also has the value of property A.

2.Function objects

Arguments objects
When a function executes, the system automatically creates a arguments object property for the function object, arguments the object property, can only be used in the function body, and uses to manage the actual parameters of the function.

(1) Caller property

The caller property shows the caller of the function, so the following example calls Function B (), and the call 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>   

(2) Length property

Length is a property of the arguments object that represents the number of arguments passed when a function is invoked, and can be accessed by an array of actual parameters.

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

Run 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.