JavaScript中的Object prototypes

/* Input: */
function doSomething(){};
console.log( doSomething );
/* Output: */
function doSomething(){}
/* Input: */														/* Input: */
function doSomething(){}											function doSomething(){}
var doSomeInstancing = new doSomething();
console.log( doSomeInstancing );									console.log( doSomething.prototype );
/* Output: */														/* Output: */
doSomething {}
{
	__proto__: Object												Object {constructor: function}
	{																{
		constructor: function doSomething()								constructor: function doSomething()
		__proto__: Object												__proto__: Object
		{																{
			constructor: function Object()									constructor: function Object()
			hasOwnProperty: function hasOwnProperty()						hasOwnProperty: function hasOwnProperty()
			isPrototypeOf: function isPrototypeOf()							isPrototypeOf: function isPrototypeOf()
			propertyIsEnumerable: function propertyIsEnumerable()			propertyIsEnumerable: function propertyIsEnumerable()
			toLocaleString: function toLocaleString()						toLocaleString: function toLocaleString()
			toString: function toString()									toString: function toString()
			valueOf: function valueOf()										valueOf: function valueOf()
		}																}
	}																}
}
/* Input: */														/* Input: */
function doSomething(){}											function doSomething(){}
doSomething.prototype.foo = "bar";									doSomething.prototype.foo = "bar";
console.log( doSomeInstancing );									console.log( doSomething.prototype );
/* Output: */														/* Output: */
doSomething {}
{
	__proto__: Object												Object {foo: "bar", constructor: function}
	{																{
		foo: "bar"														foo: "bar"
		constructor: function doSomething()								constructor: function doSomething()
		__proto__: Object												__proto__: Object			
		{																{
			constructor: function Object()									constructor: function Object()
			hasOwnProperty: function hasOwnProperty()						hasOwnProperty: function hasOwnProperty()
			isPrototypeOf: function isPrototypeOf()							isPrototypeOf: function isPrototypeOf()
			propertyIsEnumerable: function propertyIsEnumerable()			propertyIsEnumerable: function propertyIsEnumerable()
			toLocaleString: function toLocaleString()						toLocaleString: function toLocaleString()					
			toString: function toString()									toString: function toString()
			valueOf: function valueOf()										valueOf: function valueOf()
		}																}
	}																}
}
/* Input: */														/* Input: */
function doSomething(){}											function doSomething(){}
doSomething.prototype.foo = "bar";									doSomething.prototype.foo = "bar";
doSomeInstancing.prop = "some value";								doSomeInstancing.prop = "some value";
console.log( doSomeInstancing );									console.log( doSomething.prototype );
/* Output: */														/* Output: */
doSomething {prop: "some value"}									
{
	prop: "some value"
	__proto__: Object												Object {foo: "bar", constructor: function}
	{																{
		foo: "bar"														foo: "bar"
		constructor: function doSomething()								constructor: function doSomething()
		__proto__: Object												__proto__: Object
		{																{
			constructor: function Object()									constructor: function Object()
			hasOwnProperty: function hasOwnProperty()						hasOwnProperty: function hasOwnProperty()
			isPrototypeOf: function isPrototypeOf()							isPrototypeOf: function isPrototypeOf()
			propertyIsEnumerable: function propertyIsEnumerable()			propertyIsEnumerable: function propertyIsEnumerable()
			toLocaleString: function toLocaleString()						toLocaleString: function toLocaleString()
			toString: function toString()									toString: function toString()
			valueOf: function valueOf()										valueOf: function valueOf()
		}																}
	}																}
}
function doSomething(){}
var doSomeInstancing = new doSomething();
doSomething.prototype.foo = "bar";
doSomeInstancing.prop = "some value";
console.log( doSomeInstancing.prop );	   // some value
console.log( doSomeInstancing.foo );	   // bar
console.log( doSomething.prop );		   // undefined
console.log( doSomething.foo );			   // undefined
console.log( doSomething.prototype.prop ); // undefined
console.log( doSomething.prototype.foo );  // bar
console.log( doSomething );				   // function doSomething(){}

参考文章:对象原型

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值