Web Learning Diary 11.js The difference between using a function without parentheses
This problem was encountered in the technical sharing (original link; http://www.imooc.com/wenda/detail/237566) of Mu-net, before it was puzzled before the opportunity was solved.
Title Code:
1 varFullName = ' John Doe ';2 varobj = {3FullName: ' Colin ihrig ',4 prop: {5FullName: ' Aurelio De Rosa ',6Getfullname:function() {7 return This. FullName;8 }9 }Ten }; One Console.log (Obj.prop.getFullname ()); A varTest =Obj.prop.getFullname; -Console.log (Test ());
The first time I looked at this question, I was a little confused, I can know the purpose of this topic is probably the place I have been puzzled.
The first analysis came down with the result: Aurelio De Rosa and Aurelio De Rosa. It feels wrong to read the answer, and the second output is John Doe. Do not understand, this is the method of the Obj object, the first output is undoubtedly Aurelio De Rosa, the key is the second one. Reflected in the code is the question of this sentence:
var test = Obj.prop.getFullname;
I notice here that the method Getfullnam is without parentheses, and the problem should be here. Start surfing the web for answers. After reading a few, simply say my understanding.
A reference to a function without parentheses is equivalent to assigning a reference to the Getfullname function to test. The parentheses function is the execution of the function, returning the result of the function.
Another special thing about this topic is that Getfullname has this inside this method, the first time it is called, this refers to the Obj object. When assigned to test, this is the global. So when you call Test (), the natural output is the global FullName, which is John Doe.
My understanding is that, for example, this method is a measure in the United States, very effective, China see this very good, copy a set over, but there is a measure of the "first people to do something." Originally in the United States, this is naturally Washington D.C. The people, but in China, this is the people of Beijing. Haha, it is quite good to come to understand.
Three units of 2.font-size
PX: pixels for screen output such as computers.
EM: Scale is achieved by proportional form.
PT: For the output of the printer, the function is limited.
In general, PX and EM are used better.
3.html tags
HTML output Space (semicolon cannot be lost)
<HR/>: Empty label, draw the next horizontal line on the page.
The first day, over.
Web Learning Diary 1