Home > Web Front-end > JS Tutorial > body text

Introduction to the three roles of functions in js

零下一度
Release: 2017-06-29 09:41:59
Original
1672 people have browsed it

Note: Function.prototype is the value of the function data type, but the related operations are exactly the same as before->Empty/anonymous

The function itself will also have some properties of its own:

length: the number of formal parameters

name :"Fn" function name

prototype The prototype of the class, the methods defined on the prototype are all public methods of the current Fn class instance

__proto__ treats the function as an ordinary object, pointing to the prototype of the Function class

Function is the most complex and important knowledge in the entire JS:

 1. A function has multiple aspects:

  "Ordinary function": It is an ordinary function in itself. During execution, a private scope (closure) will be formed, formal parameter assignment, pre-interpretation, code execution, and the stack memory will be destroyed or not destroyed after execution is completed

  "Class ": It has its own instance, and also has an attribute called prototype which is its own prototype. Its instances can all point to its own prototype

   "Ordinary Object": Like obj in var obj = {}, it is an ordinary object. As an object, it can have its own private attributes, and Function.prototype can also be found through __proto__

There is no necessary relationship between these three.

     function Fn(){var num = 500;this.x = 100;
        }
        Fn.prototype.getX = function(){
            console.log(this.x)
        }
        Fn.aaa = 1000;var f = new Fn;
        f.num //undefinedf.aaa//undefinedvar res = Fn();
        res//undefinedFn.aaa//1000
Copy after login

The above is the detailed content of Introduction to the three roles of functions in js. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!