我遇到了一个有点奇怪的问题,似乎无法解决!这是我正在编写的一个大型框架的一部分,但我编写了一些测试代码,也遇到了同样的问题。请看下面的代码:
!function ($, window, undefined) {
// BASE FUNCTION
var test = function (selector, context) {
return new test.fn.init(selector, context);
};
// SELECTOR FUNCTIONS
test.fn = {
selector: undefined,
init: function (selector, context) {
// Use jQuery to build selector object
this.selector = $(selector, context);
return this;
},
// Create a popup dialog
popup: function (options) {
this.selector.dialog();
}
},
// Expose Carbon to the global object
window.test = test;
}(window.jQuery, window);
现在当我使用以下内容:
test('#popupLink').popup();
我收到了一个 "TypeError: test("#popupLink").popup 不是一个函数" 的错误。我知道它部分工作,因为如果我这样做,我可以使用标准的 jQuery 函数:
test('#popupLink').selector.hide();
非常感谢您的帮助,因为我现在脑子一片空白。 提前谢谢你! :)
更新 我已经使用console.log查看了返回的对象,它只有选择器元素,这很合理,因为我没有使用原型。我该怎么解决呢?