Proficient in javascript-study notes Features,functions,object

Source: Internet
Author: User

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

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.