Jq/zepto source code analysis for beginners 05, jqzepto

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.