<mce:script type="text/javascript"><!-- var b; function obj(){ this.pro='obj pro!!'; this.ins='ins'; b = this; // return this; return new obj.prototype.init(); } obj.prototype={ init:function(){ this.pro = "prototype init pro"; this.pro2 = 'prototype pro2'; return this; }, pro:"prototype pro", pro3:"prototype pro3" } var a = new obj(); for( var i in a ){ document.write(i + "/ " + a[i] +"<br/>"); } document.write("<br/>"); for( var i in b ){ document.write(i + "/ " + b[i] +"<br/>"); } document.write("<br/>"); //以下三句说明a指向的是obj的原型 document.write( "a.hasOwnProperty('pro')=" + a.hasOwnProperty("pro")+"<br/>"); document.write( "a.hasOwnProperty('pro2')=" + a.hasOwnProperty("pro2")+"<br/>"); document.write( "a.isPrototypeOf(b)=" + a.isPrototypeOf(b) + "<br/>"); //以下三句说明b指向的obj实例 document.write( "b.hasOwnProperty('pro')=" + b.hasOwnProperty("pro")+"<br/>"); document.write( "b.hasOwnProperty('pro2')=" + b.hasOwnProperty("pro2")+"<br/>"); document.write( "b.isPrototypeOf(a)=" + b.isPrototypeOf(a) + "<br/>"); // --></mce:script> javascript面向对象学习的第一部分代码。关于原型对象和this关键字的。非常重要。