<div class="codetitle"> <span><a style="CURSOR: pointer" data="9145" class="copybut" id="copybut9145" onclick="doCopy('code9145')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code9145"> <br><script type="text/javascript"> <BR>var test = { <BR>numA: 10, <BR>objB: {}, <BR>arrC: [], <BR>init: function(){ <BR>alert(this.numA); <BR>}, <BR>sayHi: function(name){ <BR>alert("hello " + name); <BR>}, <BR>sayHelloWorld: function(){ <BR>this.sayHi("world"); <BR>}, <BR>get: function(){ <BR>var self = this; <BR>this.objB.alertNumA = function(){ <BR>alert(self.numA); <BR>} <BR>} <BR>}; <BR>var TestFunc = function(){ <BR>alert("i'm testFunc"); <BR>}; <BR>TestFunc.prototype = { <BR>extFunc: function(){ <BR>alert("this extend function's numB is " + this.numB); <BR>}, <BR>numB: 10 <BR>}; <BR>test.init(); <BR>test.sayHi("qingming"); <BR>test.sayHelloWorld(); <BR>test.get(); <BR>test.objB.alertNumA(); <BR>var testFunc = new TestFunc(); <BR>testFunc.extFunc(); <BR></script> <br> </div>