Prototype and JavaScript Object Oriented instance

JavaScript object-oriented and C # are not the same, js object is inherited from the prototype is as follows:

First, create a new function instance js 

function f () {} The function new f () when inherits all the attributes Function.

 

 Print Function with console

 

 

Can not see the source code, because it is a C (or C ++ do not remember) implementation

Function corresponds to the type, its properties will be added to the prototype example

function f () {} f.prototype.name = 'prototype property'; new f () name. 

 

 

 Figure inheritance:

 

 Other ways to access the prototype

1, __ proto__ not recommended

 

2, Object.getPrototypeOf (new f ()) in the ES5

 

Guess you like

Origin www.cnblogs.com/zhuwansu/p/11578877.html