`
kun10
  • 浏览: 12684 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论
  • lz12366: 没有safia环境,没法测试、、上面代码divs.apply存 ...
    YArray.test

YUI的mix方法

    博客分类:
  • YUI
阅读更多
YUI有一个mix方法:
Applies the supplier's properties to the receiver. By default all prototype and static propertes on the supplier are applied to the corresponding spot on the receiver. By default all properties are applied, and a property that is already on the reciever will not be overwritten. The default behavior can be modified by supplying the appropriate parameters.
这个方法可以使receiver接受supplier的属性和方法。默认情况下supplier上面的原型和静态属性会应用到receriver相应的属性上面,默认情况所有的属性都会被接受,receiver上面已有属性不会被覆写。
YUI.mix(r,s,ov,wl,mode,merge);
主要的和最常用的参数是r和s两个
r是receiver
s时supplier
ov是一个对象,标识要要覆盖的属性
wl是一个白名单,
mode是覆盖的模式
merge是一个布尔值,标示是否要对属性对象也做合并
看看里面的几种覆盖时如何实现的

Y.mix = function(r, s, ov, wl, mode, merge) {
    if (!s || !r) {
        return r || Y;
    }
//根据模式来判断,默认是Obj to Obj的
    if (mode) {
        switch (mode) {
            case 1: // proto to proto
                return Y.mix(r.prototype, s.prototype, ov, wl, 0, merge);
            case 2: // object to object and proto to proto
                Y.mix(r.prototype, s.prototype, ov, wl, 0, merge);
                break; // pass through
            case 3: // proto to static
                return Y.mix(r, s.prototype, ov, wl, 0, merge);
            case 4: // static to proto
                return Y.mix(r.prototype, s, ov, wl, 0, merge);
            default:  // object to object is what happens below
        }
    }

    // Maybe don't even need this wl && wl.length check anymore??
    var i, l, p, type;
//白名单如果有值,就对白名单里面的属性进行合并,如果有ov,那么就
    if (wl && wl.length) {
        for (i = 0, l = wl.length; i < l; ++i) {
            p = wl[i];
            type = Y.Lang.type(r[p]);//看具体的属性是什么类型的
            if (s.hasOwnProperty(p)) {//如果这个属性是p自己的
                if (merge && type == 'object') {//如果设定了merge并且属性是一个对象,那么就调用mix本身,把s[p]的属性加到r[p]上面
                    Y.mix(r[p], s[p]);
                } else if (ov || !(p in r)) {//如果允许ov或者r里面没有p,那么就在r里面加上p这个属性
                    r[p] = s[p];
                }
            }
        }
    } else {//如果没有wl
        for (i in s) {//遍历s里面的属性
            if (s.hasOwnProperty(i)) {//如果i是s本身的属性,就按规则合并属性
                if (merge && Y.Lang.isObject(r[i], true)) {
                    Y.mix(r[i], s[i], ov, wl, 0, true); // recursive
                } else if (ov || !(i in r)) {
                    r[i] = s[i];
                }
            }
        }

        if (Y.UA.ie) {//如果时IE,做一个修正。
            _iefix(r, s);
        }
    }

    return r;
};


_iefix = function(r, s) {
    var fn = s.toString;
    if (Y.Lang.isFunction(fn) && fn != Object.prototype.toString) {
        r.toString = fn;
    }
};


ie不会枚举javascript对象上面的native属性,即便这个属性被重写过。
YUI的_iefix对toString做了一个处理。
分享到:
评论

相关推荐

    YUI js方法使用列子

    YUI 是 jquery 一样网页使用的javascrpit 方法库。

    YUI 入门教程YUI 入门教程YUI 入门教程

    YUI教程YUI 入门教程YUI 入门教程YUI 入门教程

    yuicompressor-yui compressor

    yuicompressor-2.4.2.jar yuicompressor-2.4.7.jar jsZip.exe yuicompressor yui compressor js压缩工具 javascript压缩工具 css压缩工具 ------------------------------------ //压缩JS java -jar yui...

    yui_2.9.0前端UI

    YUI 库,全称Yahoo! UI Library。是一组工具和控件,用JavaScript写成, 为的是用DOM 脚本,DHTML和AJAX等技术创建丰富的网页交互式应用程序。 YUI 基于BSD协议,对所有的使用方式都是免费的。YUI 项目包括YUI 库和两...

    yui3-master.zip

    yui3-master.zip

    yuitest YUI测试工具

    YUI Test is a complete testing framework for JavaScript and Web applications. You can use the simple JavaScript syntax to write unit tests that can be run in web browsers or on the command line, as ...

    yui_2.6.0r2

    yui_2.6.0r2 yui_2.6.0r2 yui_2.6.0r2 yui_2.6.0r2 yui_2.6.0r2

    js 压缩YUI

    雅虎的东西,简单的操作很好用 使用例子:java -jar D:\yuicompressor\yuicompressor\yuicompressor.jar E:\js\all.js -o E:\wap\wap2\js\all-min.js --charset utf-8 当然要装jdk了 不然就玩完了

    yui 资源包

    yui 源码下载,3.9.0 r2 包,最新版本

    yuicompressor,给YUI Compressor添加右键命令

    YUI Compressor非常好用,特别是JS的混淆是众多JS Coding的最爱。可惜官网提供的版本都不具备右键功能,每次压缩都要cmd输入一些命令实在是繁琐,本文就介绍如何给YUI Compressor添加右键命令,方便使用。 网上已有...

    从YUI2到YUI3看前端的演变 pdf

    YUI3 引入了粒度更细的模块管理方式,通过异步 HTTP 请求加载模块、然后执行...YUI是个“学院派”的框架,以性能和严谨著称,易用性相对而言弱了一些。它能否在已经拉开的 JavaScript 框架大战中胜出,让我们拭目以待。

    从YUI2到YUI3看前端的演变

    从YUI2到YUI3看前端的演变

    YUI中文文档CHM

    YAHOO YUI 中文文档 AJAX 详细 比较好用

    yui压缩

    yui压缩

    YUI3 dialog组件

    基于YUI3的dialog组件该组件是基于YUI3开发的,功能强大,详细见http://www.qiqicartoon.com

    yahoo yui 实例教程

    利用Yahoo YUI库做的一个TREE实例,很详细的阐述了YUI的使用原理

    雅虎 用户接口库YUI

    YUI资料 雅虎 用户接口库 中文说明及如何使用学习 Yui组件分成2类:工具包和控件库 Yui 工具包 Yui 工具包利用DOM脚本来简化浏览器内的开发(in-browser devolvement),使用DHTML和AJAX的特性开发所有的Web程序。...

    YUI3 完整包

    Yahoo! UI Library (YUI) 是一个开放源代码的 JavaScript 函数库,为了能建立一个高互动的网页,它采用了AJAX, DHTML 和 DOM 等程式码技术。它也包含了许多 CSS 资源。

    YUI Compressor

    使用方法: //压缩JS java -jar yuicompressor-2.4.2.jar --type js --charset utf-8 -v src.js &gt; packed.js //压缩CSS java -jar yuicompressor-2.4.2.jar --type css --charset utf-8 -v src.css &gt; packed....

    yuicompressor-2.4.8.jar

    yuicompressor.jar是JS压缩工具、前端优化神器、yuicompressor-2.4.8.jar

Global site tag (gtag.js) - Google Analytics