JavaScript中的包装器升级(YUI)

时间:2017-10-30 05:45:06

标签: javascript wrapper yui

首先,我正在进行YUI库中从YUI 2.9升级到YUI 3.18的案例研究。 这是一个以这种方式使用YUI2声明的包装器

var MyButton = function (parentWindow, buttonElem) {
    this.parentWindow = parentWindow;
    this.id = buttonElem.id;

    MyButton.superclass.constructor.call(this, buttonElem, {
        visibility : buttonElem.style.visibility,
        className : buttonElem.className
    });
    this.element = $(this.id);
    this.button = $(this.element.querySelector("button"));
    this.button.accessKey = buttonElem.accessKey;
    parentWindow.addChildElement(this.id, this);
};

YAHOO.extend(MyButton, YAHOO.widget.Button, {
    init : function (el, userConfig) {
        el.style.visibility = userConfig.visibility;
        this.addClass(userConfig.className);
        MyButton.superclass.init.call(this, el, userConfig);
        this.subscribe("click", this.onClick, this, true);
        this.subscribe("dblclick", this.ondblClick, this, true);
        this.subscribe("focus", this.onFocus, this, true);
        this.subscribe("blur", this.onBlur, this, true);
        this.subscribe("mouseup", this.onmouseUp, this, true);
        this.subscribe("mousedown", this.onmouseDown, this, true);
    }
});

以下是尝试升级到YUI3.18后的修改后的代码

var MyButton = function (parentWindow, buttonElem) {
    this.parentWindow = parentWindow;
    this.id = buttonElem.id;

    MyButton.superclass.constructor.call(this, buttonElem, {
        visibility : buttonElem.style.visibility,
        className : buttonElem.className
    });
    this.element = $(this.id);
    this.button = $(this.element.querySelector("button"));
    this.button.accessKey = buttonElem.accessKey;
    parentWindow.addChildElement(this.id, this);
};
YUI().use('button','oop',function(Y){
Y.extend(MyButton , Y.Button, {
        init : function (el, userConfig) {
        el.style.visibility = userConfig.visibility;
        this.addClass(userConfig.className);
        MyButton.superclass.init.call(this, el, userConfig);
        this.subscribe("click", this.onClick, this, true);
        this.subscribe("dblclick", this.ondblClick, this, true);
        this.subscribe("focus", this.onFocus, this, true);
        this.subscribe("blur", this.onBlur, this, true);
        this.subscribe("mouseup", this.onmouseUp, this, true);
        this.subscribe("mousedown", this.onmouseDown, this, true);
    }
});

这显示错误“无法读取属性'toLowerCase'未定义”在该行

 MyButton.superclass.constructor.call(this, buttonElem, {

我哪里错了?我可以改变什么来达到预期效果?

注意:这只是我更改代码的代码的一部分,使用YUI2.9的代码工作正常。

0 个答案:

没有答案