日期:2014-05-16 浏览次数:20402 次
<script type="text/javascript"> var testFun = function () { var obj = new Object(); var str = ""; str += "\r\nconstructor : "; str += obj.constructor; str += "\r\ntypeof obj.constructor : "; str += typeof(obj.constructor); alert(str); /** constructor : function Object() { [native code] } //Object内部实现是函数 typeof obj.constructor : function */ } </script>
<script type="text/javascript"> function testFun () { function foo(a, b, c) { return a * b * c; } var str = ""; str += "foo params length : " + foo.length; str += "\r\ntypeof foo.constructor : " + (typeof foo.constructor); str += "\r\ntypeof foo.call : " + (typeof foo.call); str += "\r\ntypeof foo.apply : " + (typeof foo.apply); str += "\r\ntypeof foo.prototype : " + (typeof foo.prototype); str += "\r\ntypeof Object.prototype : " + (typeof Object.prototype); alert(str); /** foo params length : 3 typeof foo.constructor : function typeof foo.call : function typeof foo.apply : function typeof foo.prototype : object typeof Object.prototype : object */ } </script>
var obj1 = {}; var obj2 = {}; var obj3 = new Object(); //obj1、obj2、obj3具有相同的原型对象
var p = {}; function SomeConstructor () { //...... } SomeConstructor.prototype = p; SomeConstructor.prototype.constructor = SomeConstructor; alert(p.constructor); var obj1 = new SomeConstructor(); var obj2 = new SomeConstructor(); //obj1、obj2具有相同原型对象p //p的原型引用指向内置对象Object的