Jq/zepto source code analysis for beginners 05, jqzepto
Zepto prototype $. fn attributes:
Constructor // Number of constructor rows
ForEach: emptyArray. forEach, // All are native array Functions
Reduce: emptyArray. reduce,
Push: emptyArray. push,
Sort: emptyArray. sort,
Splice: emptyArray. splice,
IndexOf: emptyArray. indexOf,
Concat // merged array, which also contains a set of merged nodes
Add // add Node Set
Is // match whether the selector is included
find: function(selector){ var result, $this = this if (!selector) result = $() else if (typeof selector == 'object') result = $(selector).filter(function(){ var node = this return emptyArray.some.call($this, function(parent){ return $.contains(parent, node) }) }) else if (this.length == 1) result = $(zepto.qsa(this[0], selector)) else result = this.map(function(){ return zepto.qsa(this, selector) }) return result },
EmptyArray. some () http://www.cnblogs.com/jiebba/p/6514067.html can look at several js traversal different
Pluck returns the node set based on its attributes.
// Set the width and height. ['width', 'height']. forEach (function (dimension) {var dimensionProperty = dimension. replace (/. /, function (m) {return m [0]. toUpperCase ()}) $. fn [dimension] = function (value) {var offset, el = this [0] if (value = undefined) return isWindow (el )? El ['inner '+ dimensionProperty]: isDocument (el )? El.doc umentElement ['scroll '+ dimensionProperty]: (offset = this. offset () & offset [dimension] else return this. each (function (idx) {el = $ (this) el.css (dimension, funcArg (this, value, idx, el [dimension] ()})
// Add functions 'after', 'prepend', 'before', 'append ',
adjacencyOperators.forEach(function(operator, operatorIndex) { var inside = operatorIndex % 2 //=> prepend, append $.fn[operator] = function(){ // arguments can be nodes, arrays of nodes, Zepto objects and HTML strings var argType, nodes = $.map(arguments, function(arg) { var arr = []
zepto.Z.prototype = Z.prototype = $.fn
Bind to the prototype
Window. Zepto = Zepto window. $ == undefined & (window. $ = Zepto) // bind to global
The code is for reference only. The specific functions can be expanded by yourself.
Http://www.cnblogs.com/jiebba/p/6529854.html
Http://www.cnblogs.com/jiebba my blog, come on!
If any error occurs, leave a message and modify it!