About learning JavaScript books, there are too many, there are Rhino books, Red Book, but they are similar to a book, contains JS everything, and does not stand at a height, look at the nature of JS, I plan to see the jquery author Resig wrote "Proficient in JavaScript," the second edition, Take a reading note by the way.
The 2nd Chapter: Features,functions,object
-Reference and Value
There are two ways to pass and transmit the values, in many languages, but one thing to note is that reference is the object pointed to in JS and cannot point to another reference. That is: JS, reference along the prototype chain, and ultimately point to the core object.
var item = [' One ', ' both ', ' three ']; var itemref == [' Four ', ' Five '];console.log (item); Console.log (itemref); // item points to the change, but Itemref still points to the original memory.
-Context
Mention JS in the context, a JS veteran, should be the first time, think of what? Yes, definitely this. About this, the internet is really talking about too much, but how to be considered to have mastered the use of this? I think, at least you can, handwriting an example of it. So we're going to write one:
function SetValue (value) { this.value = value;} var obj = {};setvalue; obj.setvalue = Setvalue;obj.setvalue; Console.log (value); Console.log (Obj.value);
Now that you have this, it is logical that a qualified JS programmer should know the usage and the difference between call and apply.
For example, we have a function:
var Sherlock ={
Play:function (song) {
Console.log (this.name+ ' is playing ' +song);
},
Name: ' Sherlock '
};
Sherlock.play (' Hello ');
var huasheng={name: ' Huasheng '};
Sherlock.play.call (Huasheng, ' goodbye ');
Sherlock is playing Hello
Huasheng is playing goodbye
Sum of the arrays:
var ary = [1,2,3,4,5]; var max = Math.max.apply (null, ary); Console.log (max);
The special place for apply is that the parameter is an array or an array of classes, so it can be the arguments of the function.
Proficient in javascript-study notes Features,functions,object