this. operator and [] operator

Source: Internet
Author: User

First look at this two running results are not the same as the first two are 3 behind is 10

var length  = ten; var arr = [function() {Console.log (this. length);},2,3];arr[0] ();(arr[ 0]) ();(function() {Console.log (this. length);}) (); var tmpfun = arr[0];tmpfun ();

About this sentence arr[0]! = (function () {console.log (this.length);}) () They are not equal

This arr[0] is no longer taken out of the element to think that this element is an executable function arr[0] () equivalent to () This is the ARR

PS so why Arr[0] () and (arr[0]) [0] is the same? You can see this

If A.B is a function encountered (A.B) () The compiler will remove the parentheses that are executed with A.B ()

var length = ten; function fn () {  Console.log (this. length);} var obj = {  5,  function(FN) {    fn ();    arguments[0] ();  

So this topic output 10, 2 2 is the length of the arguments

this. operator and [] operator

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: 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.