prevent memory leaks jQuery (this ). Children (). remove (); // Remove Any remaining nodes while (this. FirstChild) this. RemoveChild (this. firstchild);}2. The JQuery replication node clone () method does not replicate the data cache, and it is accurate that jquery does not allocate a new node in the global cache object to hold the newly replicated Elem cache. jquery replaces the potentially existing cache pointer property (the Elem ex
} Else {This. type = src;}// TimeStamp is buggy for some events on Firefox (#3843)// So we won't rely on the native valueThis. timeStamp = jQuery. now ();// Mark it as fixedThis [jQuery. expando] = true;};Function returnFalse (){Return false;}Function returnTrue (){Return true;}// JQuery. Event is based on DOM3 Events as specified by the ECMAScript Language Binding// Http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.htmlJQue
JQuery. Data source code and jquery source code analysis
JQuery. data is the data cache system of jQuery. It is mainly used to add data for common objects or DOM elements.1. Internal Storage Principle
This principle is very simple. The data originally to be added to the DOM element is now centrally stored in the cache set. They are linked by a number key starting from 1. In this way, the DOM elements will not be as heavy as before, and there will be no memory leakage caused by previous loop re
This article mainly introduces the usage of $. data in jQuery's data cache and complete source code parsing. It provides an in-depth explanation of jQuery's implementation of reading, writing, and removing cached objects. For more information, see
I. Implementation principle:
For a DOM element, assign a unique association id to associate the DOM element with the data cache object of the DOM element. The association id is appended to jQuery. the data is stored in the global cache object jQuery.
Jq source code parsing is bound to $, the method above jQuery, jqjquery
1. The method called directly with the $ symbol. How is jQuery encapsulated? Curious?
// The jQuery. extend method is bound to $. JQuery. extend ({// expando is used to determine the uniqueness of the current page. /\ D/non-numeric. The decimal point is removed. Expando: "jQuery" + (version + Math. random ()). replace (/\ D/g, ""), // A
. now ();// Mark it as fixedThis [jQuery. expando] = true;};Function returnFalse (){Return false;}Function returnTrue (){Return true;}// JQuery. Event is based on DOM3 Events as specified by the ECMAScript Language Binding// Http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.htmlJQuery. Event. prototype = {PreventDefault: function (){This. isdefapreprevented = returnTrue;Var e = this. originalEvent;If (! E ){Return;}// If pre
");
System. Windows. Forms. MessageBox. Show (strRetVal );
Note that the javascript function name in the HTML document must be followed by an empty parenthesis (without parameters), and that empty parentheses are not required for calling in C #2.0.
How to solve this problem by using mshtml in C #1. x? Here we will introduce a work ing method (these work ins have also been used in previous articles ):1. Define variables in Form to store the return values of javascript functions;2. Use InteropSe
, jquery. data (ELEM, "handle") ;}ret = NULL; Delete events [type] ;}}) ;} // remove the expando if it's no longer used for (RET in events) brea K; If (! RET) {// remove the relevant data on the group memory var handle = jquery. data (ELEM, "handle"); If (handle) handle. ELEM = NULL; jquery. removedata (ELEM, "events"); jquery. removedata (ELEM, "handle ");}}},
jquery. event. trigger allows you to program all the callback functions of an event type o
In IE, if the version is earlier than 9, you cannot directly set Custom Attributes. You must use the setattribute method. other browsers do not have this problem.
// For example, sizzleCodeAn error occurs in ie xml. You cannot directly use el. AAA = "BBB" If (parent (parent [expando]! = Donename |! ELEM. nodeindex) {COUNT = 0; For (node = parent. firstchild; node = node. nextsibling) {If (node. nodetype = 1) {node. nodeindex = ++ count ;}} parent [
JQuery1.6.1 has been released for a while and some redundant code has been found, as listed below:
1. bind method. The last fn parameter is redundant.
View sourceprint? 1 // Handle object literals
2 if (typeof type = "object "){
3 for (var key in type ){
4 this [name] (key, data, type [key], fn );
5}
6 return this;
7}
2. Comment
View sourceprint? 1 // Add which for click: 1 === left; 2 === middle; 3 === right
Change
View sourceprint? 1 // Add which for mousedown/mouseup: 1 === left; 2 === midd
trigger parameter "! ". The output result 2 shows that the namespace event is not triggered. Summary:. Trigger ('click') triggers all click events. Trigger ('click. A') only triggers click... Trigger ('click! ') Triggers a non-namespace Click EventSeeCopy codeThe Code is as follows: if (type. indexOf (".")> = 0 ){// Namespaced trigger; create a regexp to match event type in handle ()Namespaces = type. split (".");Type = namespaces. shift ();Namespaces. sort ();}
This section is very understanda
replication node does not copy the data cache. Specifically, jQuery does not allocate a new node in the global cache object to store the new replication elem cache. In clone (), jQuery replaces the possible cache pointing attribute (expando attribute of elem) with null. If you directly copy this attribute, it will lead to both the original and new elem pointing to a data cache, and the intermediate interoperability will affect the cache variables of
For JavaScript event extensions, all lib operations are similar. With jquery, prototype, Yui, and ext, the primary problem to be solved is compatibility. All lib packages the event and unifies its attributes to solve its compatibility. Operations on events are nothing more than three event Methods: addevent, fireevent, and removeevent. Generally, lib extends the functions provided by the browser to solve problems such as compatibility Memory leakage. The third problem is how to get the domready
attribute.LengthGetPushstackEach... 3. defined evalscript Function 4. The extend method was unveiled. 5. an important attribute name expando is defined. If the jquery object needs to be cached, the object will be assigned the attribute named by this attribute, the value of this attribute is an incremental UUID value (For details, refer to the data method ).VaR expando = "jquery" + (new date (). gettime (
outerhtml, or the parent node's innerHTML, use the Clean method to parse a new element out. But outerHTML and innerHTML both have explicit attributes written in it, so they need to be cleaned out with a positive.
jQuery1.4 found IE if for object, Ember, applet these three old to access external resources of the label may be thrown wrong. Since the element node of the old IE is just a COM wrapper, once the resource is introduced, it becomes an instance of that resource, and they hav
(This.firstchild)
This.removechild (This.firstchild);
}
2. The JQuery replication node clone () method does not replicate the data cache, and it is true that jquery does not allocate a new node in the global cache object to store the new replication Elem cache. jquery replaces the possible cache-pointing attribute (Elem's expando attribute) in clone () to NULL. If you copy this attribute directly, it will cause both the original and newly
Js|jscript
The Expando property of an object in JScript is an important means of adding a member to a reference type such as Object,array, but this is not the case for a value type, such asvar str = "string1";Str.method1 = function () {Do something};
STR.METHOD1 ();//There will be an error, the error message (I forgot) is that STR does not exist in this method
Such a statement would not run, and in C # programming a value type has a boxing and unboxin
Package of 6.1 Event
Browser event compatibility is a troubling issue. IE's event is under the Global window, and Mozilla's event is the incident source parameter passed into the callback function. There are also many ways to handle events.
jquery provides a package of event, which is a little simpler than the rest of Lib, but enough to use.
Parcel out the event.Fix:function (event) {if (event [expando] = = True) return event;//indicates that the e
faster than Code 1.
5. Do not use var f = function g () {function body ...}Code:// Code 1Var f = function g () {}; typeof g; // "function"// Code 2Typeof g; // "function" var f = function g (){};// Code 3Var f = function g () {}; f === g; // false f. expando = 'foo'; g. expando; // undefined// Code 4Var f = function g () {return 1 ;}; if (false) {f = function g () {return 2 ;};} g (); // 2Say:Code 1 and 2
events.
See
The Code is as follows:
If ((! Elem | jQuery. event. customEvent [type]) ! JQuery. event. global [type]) {// No jQuery handlers for this event type, and it can't have inline handlersReturn;}
For special events such as "getData" or events that have been triggered, return directly.
Down
The Code is as follows:
Event = typeof event = "object "?// JQuery. Event objectEvent [jQuery. expando]? Event:// Object literalNew jQuery. Event (ty
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.