码迷,mamicode.com
首页 > 其他好文 > 详细

YUI3 Y.Attribute

时间:2014-06-14 23:37:07      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   java   http   

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

<script src="http://yui.yahooapis.com/3.16.0/build/yui/yui-min.js"></script>
<script type="text/javascript">

    YUI.add(electron, function(Y) {

        var REST_ENERGY = 511.00;

        function Electron(config) {

            this.addAttrs({
                charge: {
                    value: -1,
                    readOnly: true
                },
                energy: {
                    value: REST_ENERGY,
                    validator: function(en) {
                        return (en >= REST_ENERGY);
                    }
                }
            }, config);

        }
        Y.Electron = Y.augment(Electron, Y.Attribute);
    }, 0.0.1, {requires: [attribute]});

    YUI().use(electron, function(Y) {

        var e1 = new Y.Electron({charge: 10, energy: 311});
        Y.log("charge: " + e1.get(charge));
        Y.log("energy: " + e1.get(energy));


        var e2 = new Y.Electron();
        e2.on(chargeChange, function(ev) {
            Y.log("charge on");
        });

        e2.after(chargeChange, function(ev) {
            Y.log("charge after");
        });

        e2.on(energyChange, function(ev) {
            Y.log("energy on");
            Y.log(ev.prevVal + " ------- " + ev.newVal);
        });

        e2.after(energyChange, function(ev) {
            Y.log("energy after");
        });

        e2.set(charge, 123);
        e2.set(energy, 1003);
    });
</script>
</body>
</html>

 

YUI3 Y.Attribute,布布扣,bubuko.com

YUI3 Y.Attribute

标签:style   class   blog   code   java   http   

原文地址:http://www.cnblogs.com/weats/p/3786035.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!