Discussed here under the object's internal prototype (__proto__) and the prototype of the constructor (prototype).
一、所有构造器/函数的__proto__都指向Function.prototype,它是一个空函数(Empty function)

Number.__proto__===Function.prototype//true
Boolean.__proto__===Function.prototype//true
String.__proto__===Function.prototype//true
Object.__proto__===Function.prototype//true
Function.__proto__===Function.prototype//true
Array.__proto__===Function.prototype//true
RegExp.__proto__===Function.prototype//true
Error.__proto__===Function.prototype//true
Date.__proto__===Function.prototype//true

JavaScript中有内置(build-in)构造器/对象共计12个(ES5中新加了JSON),这里列举了可访问的8个构造器。 The remaining as Global can't directly access, the Arguments in a function call only when created by JS engines, Math, JSON exists in the form of objects, without new. Their __proto__ is Object. The prototype. The following

math.h __proto__===Object. The prototype//true.
JSON __proto__===Object. The prototype//true

it says "all the constructor/function" of course, including the custom. The following

//function declaration
function Person () {}

var//function expression Man=function () {}
the console. The log (Person. __proto__===function. The prototype)//true.
console log (Man. __proto__===function. The prototype)//true

this means what?
all constructors from the Function. The prototype, even including the root Object and the Function of the constructor itself. All inherited constructor Function. The properties and methods of the prototype. Such as length, the call, the apply and bind (ES5). .
the Function prototype is the only a typeof XXX. The prototype for the "Function" of the prototype. Other constructor's prototype is an object. 如下

console.log(typeof Function.prototype)//function
console.log(typeof Object.prototype)//object
console.log(typeof Number.prototype)//object
console.log(typeof Boolean.prototype)//object
console.log(typeof String.prototype)//object
console.log(typeof Array.prototype)//object
console.log(typeof RegExp.prototype)//object
console.log(typeof Error.prototype)//object
console.log(typeof Date.prototype)//object
console.log(typeof Object.prototype)//object

噢,上面还提到它是一个空的函数,alert(Function.prototype) 下看看。
to know all the constructor (including built-in and custom) __proto__ is Function. The prototype of the Function. The prototype __proto__ is who?
believe all heard about JavaScript functions are first-class citizens, which can reflect the from? The following

the console. The log (Function. The prototype. __proto__===Object. The prototype)//true

this shows all the constructor is an ordinary JS Object, you can add/remove attributes to the constructor, etc. At the same time it also inherited Object. The prototype of all methods: toString, the valueOf, hasOwnProperty, etc.
the last Object. The prototype __proto__ is who?

Object. The prototype. __proto__===null//true

has been finished, null.
2, all __proto__ object points to its constructor's prototype
the above tested all built-in constructor and custom constructor __proto__, look at all these below the constructor who __proto__ pointing to the instance of the object?
先看看JavaScript引擎内置构造器

var obj={name: 'jack'}
var arr=[1,2,3]
var reg=/hello/g
var date=new Date
var err=new Error('exception')
console.log(obj.__proto__===Object.prototype)//true
console.log(arr.__proto__===Array.prototype)//true
console.log(reg.__proto__===RegExp.prototype)//true
console.log(date.__proto__===Date.prototype)//true
console.log(err.__proto__===Error.prototype)//true

再看看自定义的构造器,这里定义了一个Person

function Person(name) {
this.name=name
}
var p=new Person('jack')
console.log(p.__proto__===Person.prototype)//true

p是Person的实例对象,p的内部原型总是指向其构造器Person的prototype。
每个对象都有一个constructor属性,可以获取它的构造器,因此以下打印结果也是恒等的

function Person(name) {
this.name=name
}
var p=new Person('jack')
console.log(p.__proto__===p.constructor.prototype)//true

上面的Person没有给其原型添加属性或方法,这里给其原型添加一个getName方法

function Person(name) {
this.name=name
}
//修改原型
Person.prototype.getName=function() {}
var p=new Person('jack')
console.log(p.__proto__===Person.prototype)//true
console.log(p.__proto__===p.constructor.prototype)//true

可以看到p.__proto__与Person.prototype,p.constructor.prototype都是恒等的,即都指向同一个对象。
if set the prototype in another way, the result is somewhat different

function Person (name) {
this. Name=name
}

//rewrite prototype Person. The prototype={
getName: function () {}
}
var p=new Person (" jack ")
the console. The log (p. __proto__===Person. The prototype)//true.
console log (p. __proto__===p.c onstructor. Prototype)//false

here directly to rewrite the Person. The prototype (note: a sample is to modify the prototype). Output can be seen that p. __proto__ is still pointing to the Person. The prototype, rather than the p.c onstructor. The prototype.
it is easy to understand, give a Person. The prototype is an Object of value assignment directly measured {getName: function () {}}, using direct quantity> Object defines the Object of the constructor (a constructor) points to is the root of the constructor Object, the Object. The prototype is an empty Object {}, {} nature and {getName: function () {}}. The following

var p={}
the console. The log (Object. The prototype)//as an empty Object {}
the console. The log (p.c onstructor===Object)//direct quantity> Object defines the Object of the constructor for the Object.
console log (p.c onstructor. Prototype===Object. The prototype)//is true, don't explain

__proto__ is currently used in the above code in IE6/7/8/9 don't support. Object can be used in ie 9. GetPrototypeOf (ES5) access to the Object's internal prototype.

var p={}
var __proto__=Object. GetPrototypeOf (p)
the console. The log (__proto__===Object. The prototype)//true

you might be interested in the article:

  • JS prototype object pop " Style "
  • introduction to javascript prototype inheritance
  • js prototype chain principle picture
  • javascript prototype inheritance introduction
  • javascript prototype inherit to the constructor of the
  • javascript prototype inherited the basis of mechanism analysis of
  • javascript prototype property in-depth introduction
  • javascript as and inheritance of object-oriented
  • understand the prototype javascript attribute
  • javascript code sniffer extension of native objects and prototype (prototype)


This concludes the body part