码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript 三种创建对象的方法2

时间:2015-09-18 23:30:30      阅读:416      评论:0      收藏:0      [点我收藏+]

标签:

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);

}

 

JavaScript 三种创建对象的方法2

标签:

原文地址:http://www.cnblogs.com/hzzhero/p/4820483.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!