静态:共享

一、公有静态成员(作为函数的属性即可):

 var Gadget = function(price) {
this.price = price;
}
Gadget.isShiny = function(){
var msg = 'you bet';//公有静态
if(this instanceof Gadget){//实例调用时
msg += ', it costs ' + this.price + '!';
}
return msg;
}
Gadget.prototype.isShiny = function(){
return Gadget.isShiny.call(this)
} console.log(Gadget.isShiny());//you bet 此为静态调用
var a = new Gadget(23);
console.log(a.isShiny());//you bet, it costs 23! 此为实例调用

二、私有静态成员:

  私有:构造函数外部不可访问

  静态:所有实例共享

通过即时函数创建作用域存放

 var Person;
(function(){
var id = 0;//私有
Person = function(){
id ++;
this.id = id;
}
Person.prototype.getId = function(){
console.log(this.id);
}
Person.prototype.getLastId = function(){
console.log(id);
} })(); var p1 = new Person();
p1.getLastId();//
p1.getId();// var p2 = new Person();
p2.getLastId();//
p2.getId()// var p3 = new Person();
p3.getLastId();//
p3.getId();// p1.getId();//
p2.getId();//
p3.getId();//

注:JavaScript设计 P108-111 略变

最新文章

  1. 如何通过一个类名找到它属于哪个jar包?
  2. Linux操作系统学习笔记
  3. asp控件Repeater运用
  4. HTTP中缓存相关
  5. GAC write failed when upgrade with InstallShield
  6. Normalize.css 介绍与源码解读
  7. STM32硬件IIC操作
  8. Zookeeper3.4.9分布式集群安装
  9. 用python画一朵玫瑰花
  10. RobotFrame连接MySql数据库
  11. 使用requirejs来管理angularJS依赖示例
  12. Django1-HTTP协议介绍
  13. (转载)js日期格式化转化
  14. Python 计算当真因子个数为偶数个时为幸运数,计算区间内幸运数之和
  15. Python 浅拷贝copy()与深拷贝copy.deepcopy()
  16. P2602 [ZJOI2010]数字计数
  17. [CC-BSTRLCP]Count Binary Strings
  18. [转]Angular2: Cannot read property 'name' of undefined
  19. 从 Firefox 35 版本开始,就无法兼容 PAC 式代理
  20. 20165214 实验一 Java开发环境的熟悉

热门文章

  1. Webform(六)——登录状态保持(Cookies内置对象)
  2. mysql数据类型
  3. 由用友NC刷新功能得到启示
  4. screen:多重视窗管理程序
  5. CentOS安装JDK-1.7
  6. Jmeter添加硬件监控
  7. JSON字符串和JS对象之间的转换
  8. Selenium-java-testng插件安装eclipse
  9. 转: CentOS 安装 SVN1.8 客户端
  10. Nuget 命令 NuGet 管理项目库