Home >Web Front-end >JS Tutorial >Some precautions in javascript, updating_javascript skills

Some precautions in javascript, updating_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:14:191012browse
1. Prototype prototype objects, the principles that need to be paid attention to are:
(1). Using prototypes can greatly reduce the memory requirements of each object, because objects can inherit many attributes.
(2). Objects can inherit properties even if they are added to the prototype after the object is created.
Sample code:
Copy code The code is as follows:



The running result is:
prototype attribute:
1. Using prototypes can greatly reduce the memory usage of each object Required because objects can inherit many properties.
2. Objects can inherit properties even if they are added to the prototype after the object is created.

2. Both setTimeout and setInterval functions are defined in the window object. The function of setTimeout(fun_name, time_minisec) is to run the fun_name function once after time; the function of setInterval(fun_name, time_minisec) is to run the fun_name function every time_sec. The sample code is as follows:

Copy the code The code is as follows:










3. Local objects, built-in objects and host objects
1. Local objects include Object, Function, Array, String, Boolean, Number, Date, RegExp, Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, and URIError are all reference types defined by ECMA-262.
2. Built-in objects: All objects provided by the ECMAScript implementation, independent of the host environment, appear when the ECMAScript program starts executing (ECMA-262 definition). There are only two built-in objects, Global and Math, both of which are local objects. . Built-in objects are a special kind of local objects.
3. Host object: All non-local objects are host objects, that is, objects provided by the host environment implemented by ECMAScript.
In short, local objects are those officially defined objects. Built-in objects are a type of local objects, which only include Global objects and Math objects. Host objects are those that are not officially defined and are composed of objects you build yourself plus DOM and BOM objects.

4. The use of Array.prototype.slice.call(_array,begin[,end]) is equivalent to _array.slice(begin[,end]), but Array.prototype.slice. The efficiency of call is much higher than the second usage.
Example:
function p(msg)
{
document.write(msg,'
');
}
p(Array. prototype.slice.call([1,2,3,4],2));
p([1,2,3,4].slice(2));
Run result:
3,4
 3,4
(Note: Recording these contents is just for easy reference in the future, as a record of my own knowledge accumulation. Many of them refer to resources on the Internet, and I will not write down the sources one by one. Please forgive me.)
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn