JavaScript对象常用操作

发布于 2018-12-28  311 热度


创建对象

  • 创建空对象后赋值
person=new Object();
person.firstname="Bill";
person.lastname="Gates";
person.age=56;
person.eyecolor="blue";
  • 替代语法(使用对象 literals):
person={firstname:"John",lastname:"Doe",age:50,eyecolor:"blue"};
  • 使用对象构造器
function person(firstname,lastname,age,eyecolor)
{
    this.firstname=firstname;
    this.lastname=lastname;
    this.age=age;
    this.eyecolor=eyecolor;
}
person1=new person("Bill","Gates",20,"blue");

持续更新中


我一直在开辟我的天空