This article mainly introduces how to use jQuery. the source code of extend analyzes the implementation principle and usage of the extend method in JQuery. It is very detailed. We recommend it to you here. If you need it, refer to it. I haven't posted a post for a long time. Today I suddenly analyzed the implementation principle of the extend method in JQuery. Th
plug-in understanding. $.extend () and $.fn.extend ()Plug-in development includes two kinds: 1. The class-level plug-in development, i.e. $.extend () extends the jquery object itself; 2. The object-level plug-in development, or $.fn.extend () extends the jquery element set to provide new methods.1. Class-level plug-in development1. (function ($) {$.extend ({Hello
CSS above, because when a variable is defined two times, the last definition takes effect. Like in CSS, a different CSS style is defined for the same element, and the last definition takes effect. Like the following.{ @var: 1; . class { @var: 2; Three: @var; @var: 3; } One : @var;}After compilation{ three: 3;} { one: 1;}Extend:The extension selector is less pseudo-class selector, he will copy the current selector, define the new style, and the original inconvenience{ :
It is important to clarify the relationship between use cases when drawing a use case diagram. The relationships of use cases include generalization, extended, and include ). Include and extend are the most confusing. Next we will thoroughly clarify the relationship between the three Based on the instance.
Basic ConceptsUse case diagram: the use case diagram shows who is the relevant user, what services (Use Cases) The user wants the system to provide
Jquery.extend = JQuery.fn.extend = function () {Define some variablesif () {} See if it is a deep copy caseif () {} See the parameter is correctif () {} see if plug-in situationfor () {There may be multiple object conditionsif () {} Prevents circular references, such as $.extend (A, {name:a}); The case of circular references is excluded;if () {} deep copyelse if () {} shallow copy}}Knowledge Point carding:1, jquery is a function, jquery () returns an
Brief Introduction
We often see the assign,extend,merge function in someone else's code, which is similar to the three functions that merge the properties of the source object into the target object.
Since all are merging objects, why are there three different functions? What is the difference between them? assign (object, [sources])
Let's look at the definition on the official website first:
Assigns own enumerable string keyed properties of source o
In the jquery API manual, we see that extend is actually two different ways to mount jquery and Jquery.fn, although within the jquery jquery.extend () and JQuery.fn.extend () are implemented with the same code, but their functionality is not quite the same. Take a look at the official API's explanation for extend:
The code is as follows:
Copy Code code as follows:
Jquery.extend (): Merge t
Backbone version: 0.9.2
1. parse Backbone. Model (Collection | Router | View). extend
(1). Find the extend Definition// Define the extend Function
Var extend = function (protoProps, classProps ){
/*
Usually we use Backbone. XXX. extend method to create a Model, View and ot
This article mainly introduces the implementation principles of extend functions in jQuery. extend () functions are used for development of jQuery plug-ins. This article mainly analyzes the implementation principles of extend functions, if you need it, you can refer to extend () as an important function in jQuery. it i
1.$.extend$.extend (SRC)The method is to merge src into the global object of jquery.$.extend ({Hello:function () {alert (' Hello ');}});is to merge the Hello method into the global object of jquery.$.extend ($.net,{Hello:function () {alert (' Hello ');}})This is the extension of the Hello method into the net namespace
(JQuery | Zepto). A small problem with extend, jqueryzepto
I have been working on mobile terminals recently. I am also familiar with jQuery. In addition, Zepto provides the same API as jQuery, so I chose Zepto as the development framework.
Because it is mobile development, some new ES5 APIs are also applied, such as forEach. Below are some examples of the code I wrote:
list.forEach(function(v) { return !!v;})
I naively thought that forEach is the sa
This article records a small problem that I encountered when using $. extend, as well as the cause analysis and solution. it is very practical. if you need it, you can refer to it. I have been working on mobile terminals recently. I am also familiar with jQuery. In addition, Zepto provides the same API as jQuery, so I chose Zepto as the development framework.
Because it is mobile development, some new ES5 APIs are also applied, such as forEach. Below
Jquery.fnJquery.fn = Jquery.prototype = {Init:function (selector, context) {//....//...};The original Jquery.fn = Jquery.prototype. It's certainly not strange to prototype.Although JavaScript does not have a clear class concept, it is more convenient to use a class to understand it. jquery is a well-encapsulated class, such as we use the statement $ ("#btn1 ″) to generate an instance of the jquery class.Jquery.extend (object)Adding a class method to the jquery class can be understood as adding a
The Extend method of jquery is often used in projects now, so let's look at its implementation.Speaking of extend, we must first understand the $.extend and $.fn.extend function of jquery and the differencejquery has two methods for developing plug-ins, namely:1. JQuery.fn.extend ();2. Jquery.extend ();Although JavaScript does not have a clear concept of classes,
Always confuse the extend in these two libraries, so write it down.The extend in backbone implements inheritance:1 //Helper function to correctly set up the prototype chain for subclasses.2 //Similar to ' goog.inherits ', but uses a hash of prototype properties and3 //class properties to be extended.4 varExtend =function(Protoprops, staticprops) {5 varParent = This;6 varChild ;7 8 //The
How does thinkphp extend the core class? How does thinkphp extend the core class? For example, if I want to extend the routing class, first inherit the core routing class of thinkphp, and then let thinkphp run my extended routing class instead of the original core routing class?
We have 25 minutes left. can you help me ~~
Reply to discussion (solution)
This article mainly describes how to use the extend in jquery, need friends can refer to the following In jquery, the Extend extension method prototype is:nbsp; nbsp; 1, Extend (dest,src1,src2,src3 ...); nbsp; Its meaning is to src1,src2,src3 ... Merged into Dest, the return value is the merged dest, which shows that the method is modified to dest structure aft
, so I use the worker in the background to open a thread, specifically used to stringify this JSON, Similar to this:
Copy Code code as follows:
AddEventListener ("Message", function (e) {
var data = E.data;
data = json.stringify (data);
PostMessage (data);
}, False);
Posmesage:
Copy Code code as follows:
Worker.postmessage (data)
However, the console prints the following error message:
Copy Code code as follows:
Uncaugh
Since it is a class, there is an abstract class, a specific class, and class inheritance. At the same time, the class members can have instance members and static members. Let's take a look at how prototype achieves this.First look at the following code in prototype:Copy codeThe Code is as follows:Var Abstract = new Object ();Object. extend = function (destination, source ){For (property in source ){Destination [property] = source [property];}Return d
The source code is as follows:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->VaR abstract = new object ();
Object. Extend = function (destination, source ){
For (property in source ){
Destination [property] = source [property];
}
Return destination;
}
Object. Prototype. Extend = function (object ){
Return object. Exten
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.