You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>A string can be defined using single or double quotes. You can nest single quotes inside of double quotes, and the other way round. To mix double quotes with double quotes, the nested ones have to be escaped with a backslash.
107
+
<p>A string can be defined using single or double quotes. You can nest single quotes inside of double quotes, and the other way around. To mix double quotes with double quotes (or single with single), the nested ones have to be escaped with a backslash.
107
108
</p>
108
109
<pre><codedata-lang="javascript">"You make 'me' sad."
109
-
'Holy "cranking" moses!'
110
+
'That\'s "cranking" good fun!'
110
111
"<a href=\"home\">Home</a>"
111
112
</code></pre>
112
113
<h3id="Built-in_Methods"> Built-in Methods </h3>
113
-
<p>A string in JavaScript has some built-in methods to manipulate the string, though the result is always a new string - or something else, eg. split returns an <ahref="http://docs.jquery.com/Types#Array" title="Types">array</a>.
114
+
<p>A string in JavaScript has some built-in methods to manipulate the string, though the result is always a new string - or something else, eg. split returns an <ahref="http://api.jquery.com/Types#Array" title="Types">array</a>.
<p>A string is designated <strong>htmlString</strong> in jQuery documentation when it is used to represent one or more DOM elements, typically to be created and inserted in the document. When passed as an argument of the <code>jQuery()</code> function, the string is identified as HTML if it starts with <code><tag ... ></code>) and is parsed as such until the final <code>></code> character. </p>
140
+
<p>For explicit parsing of a string to HTML, the <code><ahref="/jQuery.parseHTML/">$.parseHTML()</a></code> method is available as of jQuery 1.8.</p>
<p>Numbers in JavaScript are double-precision 64-bit format IEEE 754 values. They are immutable, just as <ahref="#String" title="">strings</a>. All operators common in c-based languages are available to work with numbers (+, -, *, /, %, =, +=, -=, *=, /=, ++, --).
158
+
</p>
137
159
<pre><codedata-lang="javascript">12
138
160
3.543
139
161
</code></pre>
140
-
<p>Numbers in JavaScript are double-precision 64-bit format IEEE 754 values. They are immutable, just as <ahref="#String" title="">strings</a>. All operators common in c-based languages are available to work with numbers (+, -, *, /, %, =, +=, -=, *=, /=, ++, --).
<p>Note that for-in-loop can be spoiled by extending Object.prototype (see <ahref="http://erik.eae.net/archives/2005/06/06/22.13.54" class="external text" title="http://erik.eae.net/archives/2005/06/06/22.13.54">Object.prototype is verboten</a>) so take care when using other libraries.
273
291
</p>
274
-
<p>jQuery provides a generic <ahref="http://docs.jquery.com/Utilities/jQuery.each" title="Utilities/jQuery.each">each-function</a> to iterate over properties of objects, as well as elements of arrays:
292
+
<p>jQuery provides a generic <ahref="http://api.jquery.com/jQuery.each/"><em>each</em>function</a> to iterate over properties of objects, as well as elements of arrays:
275
293
</p>
276
294
<pre><codedata-lang="javascript">jQuery.each( obj, function( key, value ) {
277
295
console.log( "key", key, "value", value );
278
296
});
279
297
</code></pre>
280
-
<p>The drawback is that the callback is called in the context of each value, therefore you lose the context of your own object if applicable. More on this below at Functions.
281
-
</p>
282
-
<p><br/>
298
+
<p>The drawback is that the callback is called in the context of each value and you therefore lose the context of your own object if applicable. More on this below at Functions.
283
299
</p>
300
+
284
301
<h3id="Boolean_default_3"> Boolean default </h3>
285
302
<p>An object, no matter if it has properties or not, never defaults to false:
286
303
</p>
287
304
<pre><codedata-lang="javascript">!{} // false
288
305
!!{} // true
289
306
</code></pre>
290
307
<h3id="Prototype"> Prototype </h3>
291
-
<p>All objects have a prototype property. Whenever the interpreter looks for a property, it also checks the prototype. jQuery uses that extensively to add methods to jQuery instances.
308
+
<p>All objects have a prototype property. Whenever the interpreter looks for a property, it also checks in the object's prototype if the property is not found on the object itself. jQuery uses the prototype extensively to add methods to jQuery instances. Internally, jQuery makes <code>jQuery.fn</code> an alias of <code>jQuery.prototype</code> so you can use either one (though plugin developers have standardized on <code>fn</code>).
292
309
</p>
293
310
<pre><codedata-lang="javascript">var form = $("#myform");
294
-
form.clearForm; // undefined
295
-
form.fn.clearForm = function() {
311
+
console.log( form.clearForm ); // undefined
312
+
313
+
// jQuery.fn == jQuery.prototype
314
+
jQuery.fn.clearForm = function() {
296
315
return this.find( ":input" ).each(function() {
297
316
this.value = "";
298
317
}).end();
299
318
};
300
-
form.clearForm() // works for all instances of jQuery objects, because the new method was added to the prototype
319
+
320
+
// works for all instances of jQuery objects, because
321
+
// the new method was added to the prototype
322
+
console.log( form.clearForm ); // function
323
+
form.clearForm();
301
324
</code></pre>
302
-
<p><br/>
303
-
(This example needs clarification: how does it modify the prototype when the word "prototype" doesn't appear anywhere? The implication is that form.fn is simply an alias for form.prototype, but if that's the case then it should be explained. :-?)
304
-
</p>
305
-
<p>In javascript:the definitive guide 5 edition,dont add attibute to Object.prototype
306
-
</p>
325
+
307
326
<h2id="Array"> Array </h2>
308
327
<p>Arrays in JavaScript are mutable lists with a few built-in methods. You can define arrays using the array literal:
<p>jQuery provides a generic <ahref="http://docs.jquery.com/Utilities/jQuery.each" title="Utilities/jQuery.each">each-function</a> to iterate over element of arrays, as well as properties of objects:
361
+
<p>jQuery provides a generic <ahref="http://api.jquery.com/jQuery.each/"><em>each</em>function</a> to iterate over element of arrays, as well as properties of objects:
343
362
</p>
344
363
<pre><codedata-lang="javascript">var x = [ 1, 2, 3 ];
345
364
jQuery.each( x, function( index, value ) {
346
365
console.log( "index", index, "value", value );
347
366
});
348
367
</code></pre>
349
-
<p>The drawback is that the callback is called in the context of each value, therefore you lose the context of your own object if applicable. More on this below at Functions.
368
+
<p>The drawback is that the callback is called in the context of each value and you therefore lose the context of your own object if applicable. More on this below at Functions.
350
369
</p>
351
370
<p>The length property can also be used to add elements to the end of an array. That is equivalent to using the push-method:
<p>A selector is used in jQuery to select DOM elements from a DOM document. That document is, in most cases, the DOM document present in all browsers, but can also be a XML document received via AJAX.
525
-
</p>
526
-
<p>The selectors are a composition of CSS and custom additions. XPath selectors are available as a plugin.
543
+
<p>A selector is used in jQuery to select DOM elements from a DOM document. That document is, in most cases, the DOM document present in all browsers, but can also be an XML document received via AJAX.
527
544
</p>
528
-
<p>All selectors available in jQuery are documented on the <ahref="http://docs.jquery.com/Selectors" title="Selectors">Selectors API page</a>.
545
+
<p>The selectors are a composition of CSS and custom additions. All selectors available in jQuery are documented on the <ahref="http://api.jquery.com/category/selectors" title="Selectors">Selectors API page</a>.
529
546
</p>
530
547
<p>There are lot of plugins that leverage jQuery's selectors in other ways. The validation plugin accepts a selector to specify a dependency, whether an input is required or not:
531
548
</p>
@@ -591,10 +608,10 @@ <h2 id="jqXHR"> jqXHR </h2>
591
608
<p>As of jQuery 1.5, the <ahref="http://api.jquery.com/jQuery.ajax/">$.ajax()</a> method returns the jqXHR object, which is a superset of the XMLHTTPRequest object. For more information, see the <ahref="http://api.jquery.com/jQuery.ajax/#jqXHR">jqXHR section of the $.ajax entry</a>
592
609
</p>
593
610
<h2id="Deferred"> Deferred Object</h2>
594
-
<p>As of jQuery 1.5, the <ahref="http://api.jquery.com/category/deferred-object">Deferred</a> object provides a way to register multiple callbacks into self-managed callback queues, invoke callback queues as appropriate, and relay the success or failure state of any synchronous or asynchronous function.</a>
611
+
<p>As of jQuery 1.5, the <ahref="http://api.jquery.com/category/deferred-object">Deferred</a> object provides a way to register multiple callbacks into self-managed callback queues, invoke callback queues as appropriate, and relay the success or failure state of any synchronous or asynchronous function.
595
612
</p>
596
613
<h2id="Promise"> Promise Object</h2>
597
-
<p>This object provides a subset of the methods of the <ahref="http://api.jquery.com/category/deferred-object">Deferred</a> object (<ahref="http://api.jquery.com/deferred.then/"><code>then</code></a>, <ahref="http://api.jquery.com/deferred.done/"><code>done</code></a>, <ahref="http://api.jquery.com/deferred.fail/"><code>fail</code></a>, <ahref="http://api.jquery.com/deferred.always"><code>always</code></a>, <ahref="http://api.jquery.com/deferred.pipe/"><code>pipe</code></a>. <ahref="http://api.jquery.com/deferred.isResolved/"><code>isResolved</code></a>, and <ahref="http://api.jquery.com/deferred.isRejected/"><code>isRejected</code></a>) to prevent users from changing the state of the Deferred.</a>
614
+
<p>This object provides a subset of the methods of the <ahref="http://api.jquery.com/category/deferred-object">Deferred</a> object (<ahref="http://api.jquery.com/deferred.then/"><code>then</code></a>, <ahref="http://api.jquery.com/deferred.done/"><code>done</code></a>, <ahref="http://api.jquery.com/deferred.fail/"><code>fail</code></a>, <ahref="http://api.jquery.com/deferred.always"><code>always</code></a>, <ahref="http://api.jquery.com/deferred.pipe/"><code>pipe</code></a>. <ahref="http://api.jquery.com/deferred.isResolved/"><code>isResolved</code></a>, and <ahref="http://api.jquery.com/deferred.isRejected/"><code>isRejected</code></a>) to prevent users from changing the state of the Deferred.
598
615
</p>
599
616
<h2id="Callbacks">Callbacks Object</h2>
600
617
<p>A multi-purpose object that provides a powerful way to manage callback lists. It supports adding, removing, firing, and disabling callbacks. The Callbacks object is created and returned by the <code>$.Callbacks</code> function and subsequently returned by most of that function's methods. </p>
0 commit comments