前一篇 YUI3学习(二)--YUI Global Object
在前篇YUI3 Global Object中介绍了oop模块中的的两个继承相关的方法 extend 和augment。
本篇介绍下YUI3 oop模块剩余的几个方法。
Y.aggregate(r,s,ov.wl)
同样的基于Y.mix的属性合并方法;需要 区别Y.aggregate与Y.merge
API说明如下:
object aggregate ( r , s , ov , wl )
Applies object properties from the supplier to the receiver. If the target has the property, and the property is an object, the target object will be augmented with the supplier's value. If the property is an array, the suppliers value will be appended to the target.
如果属性是object,则根据是否覆盖参数ov,进行属性合并操作;
如果属性是array,并且ov参数为false,则根据数组索引合并属性;
如果ov参数为true,则会使用s的数组覆盖。
源码如下:
Y.aggregate = function(r, s, ov, wl) {
return Y.mix(r, s, ov, wl, 0, true);
};
示例代码:
var s={
'a':'aaaa', 'b':[1,2,3]
};
var r = {
'a':'rrrr', 'b':[4]
};
Y.mix(r,s);
alert(Y.dump(r))//{a=>rrrr,b=>[4]}
//------------------------------------
var s2 = {
'a':'aaaa', 'b':[1,2,3]
};
var r2 = {
'a':'rrrr', 'b':[4]
};
Y.aggregate(r2,s2); //等效: Y.mix(r2,s2,false,[],0,true);
alert(Y.dump(r2)) //{a=>rrrr,b=>[4,2,3]}
Y.aggregate(r2,s2,true);等效:Y.mix(r2,s2,true,[],0,true);
alert(Y.dump(r2));//{a=>aaaa,b=>[1,2,3]}
Y.clone(o,safe,func,context,owner,cloned)
详细api参考 返回对象深度克隆。
其中参数safe==true,不会克隆prototype属性; 否则克隆所有,这时,改变 prototype属性会对原始和克隆对象造成影响。
var o = {
'a':[1,2], 'b':{'name':'b1'}
}
var clonedObj = Y.clone(o);
o.a.push(3);
o.b.name = 'b1-changed';
alert(clonedObj.a) //1,2
alert(clonedObj.b.name);//b1
Y.bind(func,context,args*)
返回绑定上下文和参数值的函数。 (参数可选)
示例代码:
function Chinese(){
}
Chinese.prototype.say = function(name,msg){
alert('你好:'+name+','+msg);
}
function sayHello(name,msg){
//.....
this.say(name,msg);
}
var bindedFun = Y.bind(sayHello,new Chinese(),'YUI3');
bindedFun('i like you'); //'你好:YUI3,i like you'
Y.rbind(func,context,args*)
与Y.bind相似,返回绑定上下文和参数值的函数;不同的是绑定参数的顺序。
示例代码:(注意与Y.bind的区别)
function Chinese(){
}
Chinese.prototype.say = function(name,msg){
alert('你好:'+name+','+msg);
}
function sayHello(name,msg){
//.....
this.say(name,msg);
}
var rbindedFun = Y.rbind(sayHello,new Chinese(),'i like you');
rbindedFun('YUI3'); //'你好:YUI3,i like you'
- 大小: 3.2 KB
分享到:
相关推荐
yuicompressor-maven-plugin, 用于压缩 (Minify/Ofuscate/Aggregate) Javascript文件和使用 YUI 压缩器的CSS文件的Maven 插件 [[Flattr this git repo] ( http://api.flattr.com/button/flattr-badge-large.png)]...
yuicompressor-maven-plugin用于maven的压缩js用
eclipse 中maven项目中的 *.js *.css 文件使用 yuicompressor-maven-plugin 插件压缩
yui-yuidoc-yuidoc-50-529-gc631758
yuicompressor-2.4.2.jar yuicompressor-2.4.7.jar jsZip.exe yuicompressor yui compressor js压缩工具 javascript压缩工具 css压缩工具 ------------------------------------ //压缩JS java -jar yui...
yuicompressor.jar是JS压缩工具、前端优化神器、yuicompressor-2.4.8.jar
yui3-master.zip
yui compressor 2.4.6 发布日期:2011-04-15 用例: java -jar yuicompressor-2.4.6.jar myfile.js -o myfile-min.js
grunt-yui-compressor-源码.rar
YUI-EXT使用详解,免费送给大家
压缩JS所使用jar包!...压缩JS:java -jar yuicompressor-2.4.jar --type js xxx.js -o xxx.js --charset utf-8 压缩CSS:java -jar yuicompressor-2.4.jar --type css xxx.css -o xxx.css --charset utf-8
yui4jsf所有控件,可以和seam框架结合,已验证,源码在yui4jsf-0.6.1\net\sf\yui4jsf下
#酒店价格日历 ####基于YUI3开发的价格日历组件 @name:Y.PriceCalendar @requires:['node', 'base-base', 'event-mouseenter']
选择-yui 使用,请确保获取原生 js 文件... all ( '.yui-chosen' ) . each ( function ( ele ) { ele . plug ( Y . Chosen , { no_results_text : "Nothing found dummy." , disable_search_threshold : 4 , max_s
YUI-EXT开发学习帮助手册,自己收集网上资料整理的。
yuicompressor.jar js/css压缩 //压缩JS java -jar yuicompressor-2.4.2.jar --type js --charset utf-8 -v src.js > packed.js //压缩CSS java -jar yuicompressor-2.4.2.jar --type css --charset utf-8 -v src...