复制代代码如下: <P>// 方法一<BR>var p0 = new Object();<BR>p0.name = "xy";<BR>p0.age = 20;<BR>p0.sayName = function() {alert (この名前); }<BR>p0.showAgeAfterSomeyears = function(year) { return this.age year };<BR>p0.sayName();<BR>alert(p0.showAgeAfterSomeyears(10)); <P>// 方法二<BR>function Person(){<BR>}<BR>var p1 = new Person();<BR>p1.name = "xy";<BR>p1.age = 20; <BR>p1.sayName = function() {alert(this.name); }<BR>p1.showAgeAfterSomeyears = function(year) { return this.age year };<BR>p1.sayName();<BR>alert(p1.showAgeAfterSomeyears(10)); <P>// 方法三<BR>function person(name,age){<BR>this.name = name;<BR>this.age = age;<BR>this.sayName = function(){alert(this 。名前); }<BR>this.showAgeAfterSomeyears = function(year) { return this.age year };<BR>}<BR>var p2 = new Person("xy",20);<BR>p2.sayName();<BR>alert(p2.showAgeAfterSomeyears(10)); <P>// 方法四<BR>var p3 = {<BR>name : "xy",<BR>age : 20,<BR>sayName : function(){alert(this.name); },<BR>showAgeAfterSomeyears : function(year) { return this.age year }<BR>};<BR>p3.sayName();<BR>alert(p3.showAgeAfterSomeyears(10)); <P>// 方法五<BR>var p4 = {};<BR>p4.name = "xy";<BR>p4.age = 20;<BR>p4.sayName = function() {alert(this 。名前); }<BR>p4.showAgeAfterSomeyears = function(year) { return this.age year };<BR>p4.sayName();<BR>alert(p4.showAgeAfterSomeyears(10)); <P>