javascript开发笔记
1.1 javascript 单一模式的实现
var SingletonFactory=null;
(function(){
//instance declared
//SingletonFactory Interface
SingletonFactory = {
getInstance : getInstance
}
//private classes
function SingletonObject()
{
SingletonObject.prototype.methodA = function()
{
alert('methodA');
}
SingletonObject.prototype.methodB = function()
{
alert('methodB');
}
SingletonObject.instance = this;
}
//SingletonFactory implementions
function getInstance()
{
if(SingletonObject.instance == null)
return new SingletonObject();
else
return SingletonObject.instance;
}
})();
SingletonFactory.getInstance().methodB();
1.2 javascript :对于function 的两种观察角度
1 函数的角度
function alertWords( words)
{
alert(words);
}
2 类和对象的角度
var animal= function(){
animal.jiao=function(){alert('wo wo ')}; //animal类 相对于高级语言的静态方法。
this.eat=function(){alert('eat foot ')}; //animal类的方法
}
在new 时,首先animal 与类的原型挂钩
生成animal实体
posted on 2009-03-02 10:27 狗尾草-大数据收割基 阅读(189) 评论(0) 收藏 举报
浙公网安备 33010602011771号