1.toString () and string ()
Mode of Use: x.tostring ();-----String (x);
String is a versatile method, and x.tostring () has limitations, and cannot convert undefined and null into a string. Because the two can't be used.". Method"Forms of use.
We can now simulate the method of string () by X.tostring ().
Implementation of the idea: to make a conditional limit, if it is null--> "null" if it is undefined--> "undefined"
Otherwise, the x.tostring () is returned.
2. Overriding the IndexOf method for an array
Since IndexOf is a method of string, and the method cannot be called directly by the array, the method is very useful, so we need to let the array support the method.
First, the IndexOf method requires two parameters, Val and Fromi, one for the detection value, and one for the start subscript. Then, to determine the user-given parameters, Fromi can be omitted, the default 0.indexOf method is the core of the calendar array, do equivalent comparison.
3.forEach () and map ()
foreach is based on the original array, and the corresponding operations are performed on the arrays.
Map is to create a new array that accepts the contrived results of the original array and returns.
Redefine the principle: The calendar array, only has the element, all executes the cellback.
4.bind ()
What: Create a new function based on an existing function, the this in advance permanent binding function is the specified object--the this by default in the function refers to the object that is currently calling this function. If there is no object call function, this refers to window.
Self-tuning of anonymous functions: this in the anonymous function refers to the window, and the callback function (called in the function): The default this also refers to window;
Example: two times bind this.
$ ("#preview h1>a"). each (function (elem) {
Elem.on ("Click", This.move.bind (this));
}.bind (this));
In this case, the binding order of this is bound from the outside, because the program is executed outward (left-to-right). Outer layer binds the This of the callback function from the window to the object itself (zoom)
(That is, you can find This.move). And the bind on the inside of the callback function of this (zoom) is also tied to the this in the Move function (the default is to call the function of the object elem), so the move function of this also becomes zoom.
Functions in JavaScript that need to be self-defined