1 var person = new Object();
person.name = "zs";
person.age = 19;
2 function Persson(name ,age){
this.age = age;
this.name = name;
this.play = function(){
....
}
}
function test2(){
var p = new Person(‘zs‘,19);
alert(p.name);
}
3 使用Json语法创建js对象
function test3(){
var person ={‘name‘:‘zs‘,‘age‘:22};
alert(typeof person);
var person2 = {‘name‘:‘ls‘,‘flag‘:true,‘info‘:null};
alert(person2.info);
}
时间: 2024-11-09 09:22:10