首页 > 代码库 > YUI3 Y.extend

YUI3 Y.extend

<!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() {            Electron.superclass.constructor.apply(this, arguments);        }        Electron.NAME = electron;        Electron.ATTRS = {            charge: {                value: -1,                readOnly: true            },            energy: {                value: REST_ENERGY,                validator: function(en) {                    return (en >= REST_ENERGY);                }            }        }        Y.Electron = Y.extend(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);            }        });    }, 0.0.1, {requires: [base-base]});    YUI().use(electron, function(Y) {        var e1 = new Y.Electron({energy: 1200});        Y.log(e1.getSpeed());    });</script></body></html>