声明对象
方法1
var person = {
name: 'zhangsan',
say: function() {
alert(this.name);
}
}
person.say();
方法2
// 创建对象
function say1(Name, Age) {
// 创建对象新属性,并赋值
this.name = Name;
this.age = Age;
this.show = function() {
alert(this.name+'今年'+this.age+',说了句您好');
}
}
var lily =new say1('李丽', 22);
lily.show();
alert(lisi.name);
方法3
function Car(Name, Color) {
this.name = Name;
this.color = Color;
this.showColor = function() {
alert(this.name+","+this.color)
}
}
var car1 = new Car('car1', 'yellow');
var car2 = new Car('car1', 'blue');
car1.showColor();
car2.showColor();