jQuery Collection 介绍
This plugin generates generic collection classes, that work almost exactly as
jQuery does.
These collections include all those jQuery functions, that are used to
manipulate the collection itself.
The included built-in functions are:
add, andSelf, attr, each, end, eq, extend, filter, get, implement, include, index, init, is, map, not, pushStack, setArray, size and slice.
Every collection will have a build() function, that will create a new
collection class, that inherits from the caller. $.collection is a collection
class by itself. So other collections will inherit from it, or its subclasses.
With this plugin, you can manipulate native data types like String or
Array , with your custom methods, without actually modifying their
prototype. This is shown in some of the examples below.
If you want additional @R_890_4045@ion and more details about some of the methods.
Check this explanatory text, also included in the release.
Examples
$.collection(1,2,3,4).filter([2,3]).eq(1);//--> [ 3 ]
$.number = $.collection.build(); $.number.fn.sum = function(){ var n = 0; this.each(function(){ n += this; }); return n; }; $.number(1,2,3,4).add(5).not(function(){ return this <= 2; }).sum();//yields --> 12 ( 3 + 4 + 5 )
$.array = $.collection.build(); $.array.fn.include( Array.prototype, 'join,push' ); var $arr = $.array('I','like','xyz','jQuery').add('very').not('xyz'); $arr.push( 'much' ); $arr.join(' ');// yields --> 'I like jQuery very much'
var Nodes = $.collection.build(); Nodes.fn.init = function( elems ){ elems = document.getElementsByTagName(elems); return this.setArray( $.makeArray(elems) ); }; Nodes('body').add('script').attr('className','node');//-->[ <body>, <script>, <script> ]
var MyString = $.collection.build(); MyString.implement( String.prototype, 'replace,toupperCase'); MyString('jQuery','Quack').replace('Q','X').toupperCase()// --> [ 'JXUERY', 'XUACK' ]
Please, make sure to upgrade to 1.0.3
The plugin is very easy to master and is relatively small , less
than 2KB packed
jQuery Collection 官网
http://plugins.jquery.com/project/Collection
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。