<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("この拡張関数の numB は " this.numB); <br>}、<br>numB: 10 <br>}; <br>test.init(); <br>test.sayHi("清明"); <br>test.sayHelloWorld(); <br>test.get(); <br>test.objB.alertNumA(); <br>var testFunc = new TestFunc(); <br>testFunc.extFunc(); <br></script> <br> </div>