This article mainly introduces how to use RequireJS to optimize JavaScript reference code. RequireJS is a popular JS library, you can refer to RequireJS as an effective method to improve the speed and quality of your javascript code. It also makes your code easier to read and maintain.
In this article, I will introduce you to RequireJS and how to use it. We disc
to SetTimeout () or setinterval (), the string will be parsed as if it were using eval, which is very time consuming.Do not use:SetInterval (' dosomethingperiodically () ', +), SetTimeOut (' Dosomethingafterfiveseconds () ', 5000);And withSetInterval (dosomethingperiodically), SetTimeOut (Dosomethingafterfiveseconds, 5000);-Keep in mind that primitive operators are always more efficient than function calls. Do not var min = Math.min (A, b); A.push (v);//var min = a
In JavaScript, we generally only use push to insert new elements into the end of the array, but in fact there is another method in JavaScript, like push, that inserts new elements into the end of the array, but there is a certain difference between them. When we look at the following code, it is obvious that:1. By using the push operation array:2. Manipulate an array by using the concat:from the above two o
() {varf = window.confirm ("Are you sure this is the operation?") ");//OK add cancel popup parameter custom, return value for click OK =true, click Cancel =false;alert (f);//Print the returned boolean value}functionTestpromp () {varf = window.prompt ("Please enter user name", "Jay Chou");//prompt plus text plus OK plus cancel popup first parameter prompt, second parameter default valuealert (f);//NULL is returned when the value point in the Print input box is canceled}functionopentest () {//win
Javascript| Reference | objects | Arrays This article enumerates a variety of JavaScript objects and arrays, along with a brief description of the work done on each of these objects or arrays, and their associated property methods, and event handlers. Also note that the object or the parent of the array user may also need to refer to the Hypertext Object Hierarch
Javascript| Reference | objects | arrays
This article enumerates a variety of JavaScript objects and arrays, along with a brief description of the work done on each of these objects or arrays, and its associated property methods, as well as event handlers, which also indicate that the parent object of the object or array may also need to refer to the online Compa
This article describes a method for referencing pointers in JavaScript.
Please try to complete the following cloze:
/* Create a queue with head head0, tail for tail0
/function Intlist (head0, tail0) {
this.head = head0 | | 0;
This.tail = Tail0 | | null;
}
/* Returns a intlist containing all the numbers in the array *
/intlist.list = function (__args) {
var sentinel = new Intlist (),
len = __ Args.length,
p;
p = Senti
In Javascript scripts, the referenced parameters can be modified internally, but the references corresponding to the parameters cannot be modified. The following describes the reference principles of parameters in Javascript scripts: the referenced parameter can be modified internally (such as attributes), but the reference
functio callSum3 (num1,num2) {2return sum.call (this, num1,num2); 3 } !!! The most powerful place to apply and call is to expand the scope of the function to survive!!!1Window.color = "Red";2 varo = {color: ' Blue '};3 functionSaycolor () {4Alert This. color);5 }6Saycolor.call ( This);//Red This refers to window execution in the global environment7Saycolor.call (window);//Red similarly8Saycolor.call (o);//Blue The This object in the function body points to O, enabling the decoupling of the fu
Date typeThe date type in JavaScript is built on the Java.util.Date class in Java and uses UTC time to save the data to 285,616 years before or after January 1, 1970Create a Date object that uses the new keyword with a constructor declaration (the date object is also a reference type), and the new object automatically gets the current date and time without passing any arguments to the constructor, as follow
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
Copy Code code as follows:
function TT ()
{
Alert (11);
}
var b = TT;
var B1 = TT (); Perform the TT () function function
For a reference to a function, you can assign the function name "tt" directly to a variable, but not the function name + parenthesis form "tt ()" Because the second is to execute the function directly.
When calling a function, use the variable name + bracket form, such as: B ().
Copy Code code as follows:
f
properties. The advantage of this is that each instance will have its own copy of the instance properties, while sharing the use of the method.
Disadvantages of prototype mode : For types that contain reference type properties, when each instantiated object is said, the comparison of the reference properties of each object will be perverted.
Person.prototype ={constructor:person, Name:"Nichola
JavaScript reference type-Function
The Function type is one of the ECMAScript reference types. It is a familiar Function. Interestingly, in ECMAScript, a function is actually an object.
Each Function is a Function-type instance and has attributes and methods like other reference types.
Because the function is an object
A reference type is a more complex type. In object-oriented programming, reference types are often used, which can be said to be the core of programming languages. There are several reference types built into JS, which are described below in one by one.Built-in reference typesObject type1, declaration method: Use the n
); Returns 2parseint ("10", 8); Returns 8parseint ("10", 10); Returns 10If the decimal number contains a leading 0, it is best to use cardinality 10 so that the octal value is not unexpectedly obtained. For example:parseint ("010"); Returns 8parseint ("010", 8); Returns 8parseint ("010", 10); Returns 10The Parsefloat () method is similar to the parseint () method, viewing each character starting at position 0 until the first non-valid character is found, and then converting the string before the
parameter will be changed (accept the values of all parameters)The value we want to update must be placed on the last side, because the more the parameter, the higher the permissions. To overwrite the contents of the former duplicates.Let SourceItem = { 0, ' Learn Redux ', false}object.assign ({}, SourceItem, { true})2. Object operation: Add a new itemIn fact, as in the above, write a new key value pair even if newLet SourceItem = { 0, ' Learn Redux ', false} Object.assign
(function (Item,index,arr) {});//iterates over each item of the array, processes each item, returns the processing result of each item, and forms a new array to returnColor.foreach (function (Item,index,arr) {});//iterate over each item of an array13, the reduction methodReduce (function (prev/* */,cur/* The current item */,index/* the current item's position */,arr/* the array itself */) {//From left to right, iterating through all the items of the array, constructing a final value, returning
Let's take a look at an example:
The above example seems simple, but the result is not well understood, it is easy to think of people around-"a.x not point to object a?" Why is log (a.x) undefined? "," b.x should not be the same as a.x? Why does log come out with 2 objects?
Of course, you can first of all understand, if you can see the reason and the mechanism of work naturally there is no need to continue to look down.
The following is an analysis of the work steps of this sim
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.