oop兩種實(shí)現(xiàn)方式1.class;2原型
----原型---
prototype為函數(shù)原型對(duì)象 除(Function.prototype )沒有prototype屬性 typeof Function.prototype=function
proto為對(duì)象屬性
function a(){} a.prototype.constructor(實(shí)例自帶constructor屬性)=a
只要?jiǎng)?chuàng)建了一個(gè)新函數(shù),就會(huì)根據(jù)一組特定的規(guī)則為該函數(shù)創(chuàng)建一個(gè)prototype屬性(同時(shí)它也是一個(gè)對(duì)象),默認(rèn)情況下prototype屬性(對(duì)象)會(huì)默認(rèn)獲得一個(gè)constructor(構(gòu)造函數(shù))屬性,這個(gè)屬性是一個(gè)指向prototype屬性所在函數(shù)的指針
----原型鏈 實(shí)現(xiàn)私有等----
私有變量 var fn=function(){}
靜態(tài)變量 a.fn=function(){}
實(shí)例變量 this.fn=function(){} 實(shí)例才能用 本身用不了
https://blog.csdn.net/qq_30904985/article/details/81248613
----普通對(duì)象與函數(shù)對(duì)象---
function f1(){};
var f2 = function(){};
var f3 = new Function('str','console.log(str)');
var o3 = new f1();
var o1 = {};
var o2 =new Object();
console.log(typeof Object); //function
console.log(typeof Function); //function
console.log(typeof o1); //object
console.log(typeof o2); //object
console.log(typeof o3); //object
console.log(typeof f1); //function
console.log(typeof f2); //function
console.log(typeof f3); //function
凡是通過 new Function() 創(chuàng)建的對(duì)象都是函數(shù)對(duì)象(f1 f2 f3),其他的都是普通對(duì)象 Function Object 也都是通過 New Function()
var temp = new f1();
f1. prototype = temp;//f1. prototype為temp的實(shí)例對(duì)象