Three. Js is a great open source WebGL library, WebGL allows JavaScript GPU operation, realize the real meaning of 3 d in the browser. But the technology is still in the stage of development at present, information is very scarce, and enthusiasts learn basic and Three to go through the Demo source code. The source of js itself to learn. Introduction of
0.
the for (var a=0; a <arr. Length; +) {
//do some what
}

its execution efficiency is inferior to the following cycle:

//in the array arr.
var aLength=arr length;
the while (aLength -) {
//do some what
}

this may not help you save much cost, for the execution efficiency is mainly dependent on what did you do inside the loop body. But if you want to program to reduce unnecessary spending to the last byte, surely win after a cycle.

to be honest, the main impact or the length of the array cache of program execution efficiency. You can (and should) go to see JSPerf to understand this, and other factors, which affect the JavaScript performance.

5. Use texture//disable the mouse selected DOM element
the document. The onselectstart=function () {
return false.
};

you might want to disable the selected in the Canvas control. This is my project in the Canvas occupies the entire screen is used in the code.
8. Avoid defined in JavaScript, CSS
//as far as possible don't do that
$(" #someid "). The CSS ({
position: 'relative',
height: '30px,
width: 300px,
backgroundColor:' #A020F0 '
});

the problem is to do so, your JavaScript code soon filled with various types of CSS definitions, and you use the * at the same time. The CSS file to define the CSS, a potential problem is hard to find. A better approach is: use the class modular CSS, and only those cannot predict the CSS classes defined in JavaScript.
9. Defined in object callback function
$(" #someid "). Click (function () {

////callback function returns false in JQuery will stop message transfer and the default behavior of the free life
return false.
});

or, you will be a callback function of loosely defined elsewhere in the code, such as the

$(" #someid "). Click (mySuperFunction);
function mySuperFunction (event) {
//to do many things here
return false.
}

there will be some problem to do so. The first code, you bind the anonymous function on an event, it's hard to put the function to remove from the event. Of course, you can remove all the functions on one of the events, but you may bind the multiple functions on it, and you want to remove a. In the second case, the function name you pollute the global variable space, reduced the maintainability of the code. So, consider doing so:

$(" #someid "). Click (callbacks. MySuperFunction);
//all of the callback function in the callbacks object
var callbacks={
mySuperFunction: function (event) {
//to work more
return false.

}}

//removes a function's binding $(" #someid "). The unbind (' click 'callbacks. MySuperFunction);

do so neat and clean, and avoid the two problems mentioned above.
10.
//chain ternary operator according to the value of a numberBasedOnA assignment
//if a greater than 5, more assignment 200, otherwise the assignment 38
var numberBasedOnA=a >5? 200:38;

but if you want to do this, for example, the duty is how much, how much the duty is greater than the rate, when the duty is more big, understand? In this case, the chain the ternary operator is very nice:

var numberBasedOnA=
a <5? 200:
a <7? 38:
a <11? 15:
a <15? 49:
64;
than do so more efficiently
////when a >
=15

you might be interested in the article:

  • THREE. JS introductory tutorial (4) to create a particle system
  • THREE. JS introductory tutorial (3) under the shaders -
  • THREE. JS introductory tutorial on (2) shaders -
  • THREE. JS introductory tutorial. (1) THREE JS know before use
  • THREE. JS introductory tutorial step (6) to create your own panorama


This concludes the body part