This article lists 24 suggestions to make your code writing process easier and more efficient. Maybe you're a JavaScript beginner, just finishing up your Hello world, and there's a lot of tips that will be useful to your work; maybe some of the tricks you already know, try a quick glance and see if you can find something new.
Note: The Firebug console object is used many times in this article, please refer
24 Best Practices for JavaScript beginners1. Use = = = instead of = =JavaScript uses 2 different equivalent operators: ===|! = = and ==|! =, it is best practice to use the former in the comparison operation."If the operands on both sides have the same type and value, = = = Returns true,!== returns FALSE." "--javascript
clipboardCode:
(function doSomething() { return { name: 'jeff', lastName: 'way' };})();
22. Native JavaScript is always faster than code library.
JavaScript libraries such as jQuery and Mootools can save a lot of time for you to write code, especially when AJAX operations are required. But remember, as long as your code is properly written, native JavaScript
'};})();22. Native code is always faster than libraryJavaScript libraries, such as jquery and MooTools, can save a lot of coding time, especially AJAX operations. As has been said, always remember that libraries can never be faster than native JavaScript code (assuming your code is correct).The "Each" method of jquery is a great loop, but using native "for" statements is always faster.23. The JSON of Douglas. ParseAlthough
:
(function doSomething() { return { name: 'jeff', lastName: 'way' };})();
22. Native JavaScript is always faster than using a code base
JavaScript libraries such as jquery and MooTools can save you a lot of time writing code-especially when AJAX is needed. But remember, as long as your code is properly written, native JavaScript will always execute fas
This article lists 24 suggestions that will make your code writing process easier and more efficient. Perhaps you are a JavaScript beginner, just finished your own Hello world, there are a lot of tips for your work will be very useful, perhaps some skills you already know, then try a quick glance, see if you can find something new! 1. Use = = = Instead of ==javascript
use. It can be downloaded here.Simply by importing the script, you'll gain access to a new JSON global object, which can and be used to parse your. JSON File.var response = Json.parse (Xhr.responsetext); var container = document.getElementById (' container '); for (var i = 0, len = response.length; i
' + response[i].name + ': ' + Response[i].email + '
‘; }
. Remove "Language"Years ago, it wasn ' t uncommon to find the ' language ' attribute within script tags.However, this
Compute 24 Dots (add, subtract, multiply, divide, bracket) JavaScript version v1.0Author: 2004-04-26 Please enter four digits (1-13):In a deck of cards (52), the arbitrary extraction of 4 sheets can have 1820 different combinations, of which 458 are not 24 points.The mid 1980s, Sun Shijie from Shanghai to the United States to settle. Sun Shijie A few of the neigh
use Cssfloat,ie browser using Stylefloat. In order toMake sure all browsers are compatible and can be written as: style.cssfloat| | Box.style.styleFloat such a form.This is just a description of the way to get it, so in addition to getting a CSS style, you can also assign a value operation:Effect before assignment:The effect after assignment:The Style property can only manipulate and set CSS styles within the row for two other forms: inline Check the following code first:before adding the effec
content of the text box (input or textarea) changes and loses focus; 2 function () {3 alert (' Lee '); 4 }1 (5). Focus: Triggers on the window and related elements when the page or element has the focus; the event does not bubble; 2 function () {3 alert (' Lee '); 4 }1 (6). blur: Triggers on window and related elements when the page or element loses focus; The event does not bubble; 2 function () {3 alert (' Lee '); 4 }1 (7). Submit: Triggers on t
); } (self)); If you are unfamiliar with closures, you can poke this: from a scope chain to closure 4, to include JavaScript code in a function block what does God mean by horse? Why do you do this? In other words, why use immediate execution of function expressions (immediately-invoked functions expression). Iife has two more classic usage scenarios, one similar to timing output data items in a loop, and a plug-in and module development simi
); //interception of Slice arrays//var arr4 = Arr3.slice (2);//["C", [+] //var arr4 = Arr3.slice ( -2);//[2,3] //var arr4 = Arr3.slice (4,2);//[] //var arr4 = Arr3.slice (2,4);//["C", 1] The index value includes the coordinates that do not include the right side. //Console.log (ARR3);//Console.log (ARR4);////splice manipulating and intercepting the original array//var arr5 = ["1111", "1111", "1111"];//the//replacement element cannot exist as an array, otherwise the entire array is put int
this series as effective JavaScript 's reading notes. Suppose you need a API used to traverse several elements, like this:var it = values (1, 4, 1, 4, 2, 1, 3, 5, 6); It.next (); 1it.next (); 4it.next (); 1The corresponding implementation can be:function values () {var i = 0, n = arguments.length;return {hasnext:function () {return I But the actual implementation is:var it = values (1, 4, 1, 4, 2, 1, 3, 5, 6); It.next (); Undefinedit.next (); Undefine
A little performance improvement for JavaScript!
This article lists 24 suggestions that make your code writing process easier and more efficient. Maybe you are still a beginner in JavaScript and have just finished writing your Hello World. There are many tips that will be very useful for your work. Maybe you know some tips, let's take a quick look and see if we c
JavaScript content= "dlpower@163.com">
Compute 24 Dots (add, subtract, multiply, divide, bracket) JavaScript version v1.0Author: href= ' mailto:dlpower@163.com '>
dlpower@163.com2004-04-26 Please enter four digits (1-13):In a deck of cards (52), the arbitrary extraction of 4 sheets can have 1820 different combinations, of which 458 are not
Valid JavaScript Item 24 uses a variable to save arguments references.
This series serves as the Reading Notes for objective JavaScript.
Assume that an API is required to traverse several elements, as shown below:
var it = values(1, 4, 1, 4, 2, 1, 3, 5, 6);it.next(); // 1it.next(); // 4it.next(); // 1
The corresponding implementation can be:
function valu
(P1.name+P1.age+p1.address);Script>Body>HTML>3, Practical application: Return two number of arithmeticExample:DOCTYPE HTML>HTML>Head>MetaCharSet= ' utf-8′>title>title>Head>Body>Script>functionDisplay (yi,er) {//defining an Objectvarcounter= NewObject (); Counter.jia=Yi+Er;counter.jian=Yi–er;counter.cheng=Yi*Er;counter.chu=Yi/er;returncounter;}varobj=Display ( -, -); alert (Obj.jia+'-'+Obj.jian+'-'+Obj.cheng+'-'+Obj.chu);Script>Body>HTML>Kill lui lei Dog---Assignment operation between
Full-stack JavaScript (24) DOM2 and DOM3, which do not involve XML namespace extension, dom2dom3
(1) three attributes are added to the DocumentType change: publicId, systemId, and internalSubset (internal subset)
You can access the file by using document.doctype.publicId,document.doctype.systemId,document.doc type. internalSubset.
Export document.doc type. internalSubset will get "
(2) importNode () m
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.