YUI3的YUI构造函数

[size=large]YUI的构造函数[/size]



var YUI = function() {
var i = 0,
Y = this,//用Y来保存YUI实例
args = arguments,
l = args.length,
instanceOf = function(o, type) {//定义了instanceOf方法,用来看o是否为对象并且是否为某一个类型的实例
return (o && o.hasOwnProperty && (o instanceof type));
},
gconf = (typeof YUI_config !== 'undefined') && YUI_config;//如果YUI_config有定义那么赋值给gconf

if (!(instanceOf(Y, YUI))) {
//如果Y不是一个YUI的实例,就新new一个YUI实例
Y = new YUI();
} else {
//如果Y是YUI的实例就调用Y的_init方法
Y._init();
if (YUI.GlobalConfig) {//GlobalConfig是一个全局的配置,对所有的YUI实例都进行应用
Y.applyConfig(YUI.GlobalConfig);
}
//YUI_Config是一个页面级的配置。
if (gconf) {//gconf保存的是页面级的配置,对同一个页面的所有YUI实例都起作用
Y.applyConfig(gconf);
}

// bind the specified additional modules for this instance
//如果没有参数传给YUI函数,那么就直接执行_setup方法
if (!l) {
Y._setup();
}
}
//如果有参数,那么对参数逐个调用applyConfig方法,之后在调用_setup方法
if (l) {
// Each instance can accept one or more configuration objects.
// These are applied after YUI.GlobalConfig and YUI_Config,
// overriding values set in those config files if there is a '
// matching property.
for (; i < l; i++) {
Y.applyConfig(args[i]);
}

Y._setup();
}

Y.instanceOf = instanceOf;//把instancOf方法绑到YUI实例上面

return Y;
};



这里面调用了几个Y实例的方法
_init
_setup
applyConfig
这几个方法是在YUI构造器的prototype
稍后做分析
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值