Prototype. Prototype chain-prototype chain diagram

Source: Internet
Author: User

  1. //1.几乎所有函数都有prototype属性,这个是个指针,指向原型对象;Function.prototype这个没有
  2. //2.所有对象中都有__proto__属性.(Object.prototype该属性的值为null)
  3. //几乎所有函数都有 prototype/__proto__属性
  4. //3.函数都是Function的实例(函数是通过Function创建出来的对象)
  5. //自定义函数,Function,Array,RegExp,String,Boolean,Number,Object都是函数,都是通过Function创建出来的
  6. //4.几乎所有函数都继承自:Function.prototype
  7. //函数.__proto__===Function.prototype(除了Function.prototype本身,他没有prototype属性)
  8. //Object.__proto__===Function.prototype
  9. //Function.__proto__===Function.prototype
  10. //5.String.prototype.__proto__===Object.prototype
  11. // Array.prototype.__proto__===Object.prototype
  12. // Number.prototype.__proto__===Object.prototype
  13. // RegExp.prototype.__proto__===Object.prototype
  14. // Function.prototype.__proto__===Object.prototype
constructor normal functions are only called in different ways//=>called as a normal function.1. Within the function, this points to the called object (if no object is found, this point to window)//2. The return value of the function is determined by the return statement, if no description function has no return value (the return value is undefined) var p1 =person ( "Journey");//=> call//1 as a constructor. Creates an instance of this constructor//2. Point the value of this inside the constructor to the instance//3. Executes the function body//4. The default function value, the instance
  1. function fn(){
  2. returnthis;
  3. }
  4. var f3=new fn();
  5. console.log(f3);//fn
  6. //return {name:"张三"};
  7. //此时构造函数的返回值是一个对象就不再使用默认的返回值了,返回值就是当前的对象
  8. function fn2(){}
  9. var f2 =new fn2();
  10. console.log(fn2);//fn2的实例
  11. //如果没有返回值,会是默认的返回值
  12. //如果返回值是基本数据类型的话,还是会使用默认的返回值
var p2 = new Person ("Fan bingbing")//Function object storage feature in memory//object is also a function///combination object and function of the memory structure diagram complete understanding/Why Function.prototype is a function?// The relationship between function and Function.prototype
  1. function fn(){}
  2. console.log(fn.constructor);//Function
  3. console.log(fn.__proto__===Function.prototype);//true
  4. console.log(Object.__proto__===Function.prototype);//true
  5. console.log(Function.prototype===fn.__proto__);//true
  6. console.log(Object.constructor);// Function
  7. console.log(fn.prototype.constructor);//fn
  8. console.log(Function.prototype.__proto__.constructor);// Object
  1. var arr=["hello","say","pic"];
  2. var str3;//undefined
  3. for(var i=0;i<arr.length;i++){
  4. str3+=arr[i];//如果一个变量str3声明了没有赋值会有默认的值undefined如果参与运算的话就会出问题
  5. //所以以后再声明变量之后要给初始化的值
  6. }
  7. console.log(str3);//undefinedhellosaypic
  8. console.log(undefined+"abc");//变为一个字符串undefined abc



From for notes (Wiz)



Prototype. Prototype chain-prototype chain diagram

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.