複製代碼代碼如下: <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.ageyear };<BR>p0.sayName();<BR>alert(p0.showAgeAfterSomeYears(10));alert(p0.showAgeAfterSomeYears(10));<P> <BR>// 方法二<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.ageyear };<BR>p1.sayName();alert (p1.showAgeAfterSomeYears(10));<P> <BR>// 方法三<BR>function Person(姓名,年齡){<BR>this.name = 姓名;<BR>this.age = 年齡;<BR>this.sayName = function(){ alert(this 。 );<BR>警報(p2.showAgeAfterSomeYears(10));<BR> <BR>//方法四<BR>var p3 = {name : "xy",<P>age : 20,<BR>sayName : function(){alert(this.name); },<BR>showAgeAfterSomeYears : function(year) { return this.age 年}<BR>};<BR>p3.sayName();<BR>alert(p3.showAgeAfterSomeYears(10));<BR> <BR>//方法五<BR>var p4 = {};p4.name = "xy";<P>p4.age = 20;<BR>p4.sayName = function() {alert(this 。 <BR></腳本><BR><BR><BR>