YUI3 Y.Base.create

<!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;

        Y.Electron = Y.Base.create('electron', Y.Base, [], {

            initializer: function() {
                Y.log('init...');
            },
            getSpeed: function() {
                var e_ratio = REST_ENERGY / this.get('energy');
                return Math.sqrt(1 - e_ratio * e_ratio);
            }
        },ATTRS = {
            charge: {
                value: -1,
                readOnly: true
            },
            energy: {
                value: REST_ENERGY,
                validator: function(en) {
                    return (en >= REST_ENERGY);
                }
            }
        });

    }, '0.0.1', {requires: ['base-build']});

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

        var e1 = new Y.Electron();
        e1.set('energy', 8000);
        Y.log(e1.getSpeed());

    });
</script>
</body>
</html>

posted @ 2014-06-13 16:08  wheats  阅读(126)  评论(0编辑  收藏  举报