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

JavaScript 面向对象的3种常用写法

时间:2015-10-21 14:00:19      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

1.prototype 方式

function Person(age){
    this.Age = age;
}
Person.Sex = "男";
Person.prototype.Say = function(){
    alert(Person.Sex + this.Age);
}
var person = new Person(10);
person.Say();

 

 2.Object 方式

var Person = new Object();  
Person.Sex = "男";  
Person.Say = function(age) {  
       alert(this.Sex + age);
}  
  
Person.Say(12);

 3.匿名方式

var Person={  
   "Sex":"男",  
   "Say":function(age){  
          alert(this.Sex + age);  
     }  
};

Person.Say(12);

 

JavaScript 面向对象的3种常用写法

标签:

原文地址:http://www.cnblogs.com/chinanetwind/p/4897428.html

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