0

我有这个非常简单的 MooTools 脚本:

var MyElement = new Class({
    Extends: Element
});

这给出了错误:Uncaught TypeError: Cannot call method 'set' of null

我正在使用 MooTools 1.4.5,完全没有兼容性。

如果我更改它扩展到任何其他类的类,它工作正常。

这里发生了什么?这是一个错误吗?

编辑:

工具也会发生同样的事情:元素!

4

1 回答 1

0

As pointed out on this page:

element is not extendable as its not a real class.

This is because it is mostly an interface wrapper ('proxy') around your browser's native internal classes wrapping 'real' elements. There is a 'workaround' for this though with the toElement function. If you implement it on an object or class, passing the class to the $ function will automatically invoke it, as such making your class behave completely like an Element, and allowing you to use aggregation instead of (faulty!) inheritance to wrap browser elements.

Example of toElement.

于 2013-05-05T21:47:34.043 回答