Home » JavaScript »

also read it before. The notes contain the key points in the book and some of their own additions and Reflections.

second chapter: grammar.


JavaScript has only one numeric type. It is internally represented as a floating point.

of 64 bits

index: 100 = = 1e2

NaN: is not equal to any value, including itself. IsNaN (number)


Math method.


is an escape character.


JavaScript is created, Unicode is a 16 bit character set, so all characters in JavaScript are 16 bit.

u agreed to specify the character encoding. "A" = "u0041";

string method.


The value below

is assumed as false:

false null undefined '' 0 NaN.

all other values are treated as true. All objects.

' 0' //false = true;
If (' 0') {console.log (1)} //1


arithmetic symbol priority

/ may produce non integer results.

&&, ||

literal, function

third chapter, object


object literal is.

point or square brackets.

There is no

property returns undefined. || available to fill the default value of.


undefined retrieval error. To avoid error.

& & available


two objects are never the same unless they are the same object,.


update is connected to the prototype does not work. When we make changes to an object, the object will not touch the prototype. (if the modified attribute is a reference type, but also can change the attributes of prototype. Thinking of the example below)

function (F) {}
Var f = new F;
F.a.push (3);
F.prototype.a, //[1, 2, 3], the prototype was modified
F.A = null
F.prototype.a, //[1, 2, 3], prototype invariant.

adds a new attribute to the prototype, which immediately takes effect on all instances,.





delete can delete properties of an object. It does not touch any object in the prototype chain. If the attributes of the object are deleted, the attributes in the prototype chain may be exposed,.

reduce global variable pollution... Every book is writing this. There are also relevant records in the previous article,.

method 1. Create only one global variable for your. Var MYAPP={}. global variable container.

method two. Closure.

, fourth chapter. Function.

function object.

The object generated by the

object literal is connected to the Object.prototype. function object and connected to the Function.prototype. (the prototype object itself is connected to the Object.prototype). Consider the following interview topic:

var (F = function) {};
Object.prototype.a = function () {};
Function.prototype.b = function () {};
Var f = new, F ();
Excuse me: F.a, F.b, F.A, F.B,

Each function adds two hidden attributes when it is created. The context and the code that implements the function's behavior


function literal is.


through the function literal created that contains a connection to an external context. This is called the closure of.


this depends on call mode.


method invokes the schema. A.B (). This is its own object,.

function call mode. Add (3,4); this global object.

new mode (constructor mode). In this way, a new member of the prototype that is connected to the function will be created behind it, and the object.This will be bound to the new object,.__proto__.

apply mode. Pass in the this. and parameter array. Apply, call, bind.


does not need to specify the number of arguments.

another arguments will be consistent with the parameter.

arguments is not a true array, there is a length property. There is no array method. (but it looks like you can borrow array functions. To use array functions, you can think about the following functions.)

, function, add () {
Array.prototype.push.apply (arguments, [4,5]); / / use the array method.
Console.log (arguments);
Add (1,2,3) //[1,2,3,4,5]



function always returns. Undefined.

is returned without specifying a return value

if new. is added before the function and return is not an object, the direct quantity of the this. return is returned, and the this.

is ignored


The function of

extension type.

, for example, adds the bind function.

to browsers that do not support bind

before you add the method, you should check that the method already exists,.




has no block level scope.

for the time being


look at this example:

, function, a (nodes) {
Var i;
For (i=0, nLen = nodes.length; iNodes[i].onclick = function (E) {
Console.log (I);


module. You can build the module.

with functions and closed packets

private variables. Privilege function.

closures mask global variables.


returns this. Chain operation.

Currie. Part of.


var ADD1 = add.curry (1);

slice can return the arguements transformation to an array.



function stores the previously computed values in the function property. Avoid repeated calculations of.

produces a function of this function.

fifth chapter, inherit.

pseudo class.

forget new. Not added to the object. It is added to the global object,.

conventions initial capital.


object specifier. Parameters of the.

configuration object.



components. You can assemble objects from a set of components,.

sixth chapter, array.

array literal.


is not necessarily equal to the number of attributes in the array.


setting length is smaller than the actual deletion of the contents of the array.


delete / Arr[2] will leave a undefind.

in the array

arr.splice (2,1) / / from the beginning, delete a few digits. A large array of high efficiency.

easy to confuse place.

value.constructor = Array the situation in different window or frame.

will fail

, VaR, is_array (value) {
Return Object.prototype.toString.apply (value) = ' [object Array]';


Array.prototype.reduce = function (F, value) {
Var i;
For (i=0; iValue = f (this[i], value);
Return value;
Var data=[4,8,15,16,23,42];
Var add = function (a, b) {
Return a+b;
Var sum = data.reduce (add, 0);
Console.log (sum);

You can also add attributes to an array, such as total., that does not change his length.

specifies the initial value.

, like I wrote that Minesweeper game, generates a deep or direct literal.

with a specialized function loop