/**
* Created by kevinlou on 9/13/16.
*/
/****************************************
* 方法一
* 类、方法、属性都为静态类型
* 不能创建实例
*****************************************/
var Time = {
today: '2009-3-8',
weather: 'rain',
show: function () {
alert('Today is ' + this.today);
}
};
alert('It is ' + Time.weather + ' today.');
Time.show();
/****************************************
* 方法二
* 普通对象,同时拥有静态和非静态属性、方法
* 可以用实例化
* 注意:
* 1.静态方法/属性使用类名访问
* 2.非静态方法/属性使用实例名访问
*****************************************/
function Person(name) {
this.name = name;
this.show = function () {
alert('My name is ' + this.name + '.');
}
}
Person.mouth = 1;
Person.cry = function () {
alert('Wa wa wa …');
};
Person.prototype.teeth = 32;
var me = new Person('Zhangsan');
me.show();
alert('I have ' + me.teeth + ' teeth.');
Person.cry();
alert('I have ' + Person.mouth + ' mouth.');