【发布时间】:2012-12-11 14:56:11
【问题描述】:
我在创建我的选择器时遇到了一个问题,我确实需要像 jquery 一样拥有它 在每个 Set Chain 中的 jquery 中,它从选择器返回包含元素结果的数组,而我通过编写选择器脚本来实现这个阶段
var Ary = [];
var Selector = function(selectorFormant){
// Some Script using querySelectorAll and pushing Elements to Ary
return Ary;
}
Ary.getByTypes=function(typesString){
//Some Script here take the elements inside the Ary and get the elements inside them with the specific types typesString and repush new elements in the Ary
return Ary;
}
Selector.prototype = Ary;
Selector.prototype.constructor = Selector;
//this script is responsible for inheritance from Ary to Selector Class
我的问题是开发人员可以通过两种方式使用选择器类
1- Selector.getByTypes('types') 或
2- Selector('selector format like jquery').getByTypes('types')
在 2 中,我不必实例化一个对象来应用我执行的继承,因为方法 Selector 返回具有函数 getByTypes 的 Ary
但是在 1 中,当我不需要开发人员编写新关键字时,我必须从 Selector 实例化一个对象以应用继承来为我拥有 Ary 成员
2 我不需要那个 - new Selector('selector format').getByTypes('types');
任何人都可以帮忙:)
【问题讨论】:
-
对于“完全像 jQuery 的选择器”使用他们的 Sizzle 库,它也可以独立使用。
-
Selector.getByTypes('types')应该怎么做?这里没有选择集。 -
您知道
Ary变量是“静态的”吗? -
Selector.prototype = E;行不起作用,因为您的构造函数返回一个对象。顺便说一句,E是什么? -
很抱歉这个错误 E 它的 Ary 问题是固定的,对于嘶嘶声我知道我可以使用它,但我需要知道它是如何制作的,而不是阅读我刚刚问我的问题的所有内容 :)跨度>
标签: javascript javascript-framework