Home > Web Front-end > HTML Tutorial > Javascript Object, Function object_html/css_WEB-ITnose

Javascript Object, Function object_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:04:46
Original
1365 people have browsed it

1. Object object

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

    <script type="text/javascript">     Object.prototype.num= 10;     alert("添加原型对象属性:"+ Object.num);     Object.num = 20;     alert("添加对象属性:"+Object.num);</script>
    Copy after login

    Run results: Add prototype object attributes: 10 Add object attributes: 20

  • Prototype chain
  • Object.prototype.a = 3.14;alert("Object对象的实例:"+ new Object().a);alert("String对象的属性:"+ String.a);
    Copy after login

    Run results: Instance of Object object: 3.14 Attributes of String object: 3.14

    Analysis: When the prototype of Object is extended, it is equivalent to the object becoming Object.prototype, that is, all local objects have this The properties of the object, because all local objects inherit the Object object, String also has the value of attribute a.

    2. Function object

  • arguments object
  • When a function is executed, the system will automatically create an arguments object attribute for the function object, arguments Object attributes can only be used in function bodies and are used to manage the actual parameters of the function.

    (1) caller attribute

    The caller attribute shows the caller of the function, so in the following example, the caller of function a is function b(); the caller of 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>
    Copy after login

    Running effect:                                                                                                                                                                                                                                                                               , an actual parameter can be accessed through an array.

    The running result is 6

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

    Related labels:
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template