// 简单对象创建 var newObject = new Object(); newObject.firstName = 'frank'; newObject.sayloudly = sayloudly; newObject.sayName = sayName; var whatVolume=2; var whatFunction; if(whatVolume == 1){ whatFunction = 'sayName'; } if(whatVolume == 2){ whatFunction = 'sayloudly'; } function sayloudly(){ alert(this.firstName.toUpperCase()); } function sayName(){ alert(this.firstName); } newObject[whatFunction]();
<h3>创建对象的方法</h3> <h4>简单对象创建</h4>