Scope Chain Scope Chain

Source: Internet
Author: User

object.prototype.x = 10; var w = 20;var y = 30; Console.log (x); (function foo () {  var w = ten;  var x = +;  With ({z:50}) {    console.log (w, x, Y, z);//+, ten, +, +  console.log (this.x, THIS.W);//,  cons Ole.log (WINDOW.W); 20}) ();

  

object.prototype.x = 10; var w = 20;var y = 30; Console.log (x); (function foo () {  var w = ten;  var x = +;  With ({z:50}) {    console.log (THIS.W, this.x, This.y, z);//+, ten, 100,  console.log (x, W);//, 40  Console.log (WINDOW.W);//20}) ();

  

Search for __parent__ before searching for __proto__.

Closure function

object.prototype.x = 10; var w = 20;var y = 30; Console.log (x); (function foo () {  var w = ten;  var x = +;    (function () {   Console.log (w, x, y);//40,100,30}) ();}) ();

 

Because with will produce a temporary scope during run time, the closure function is within the scope of Foo.

Original: http://www.nowamagic.net/librarys/veda/detail/1645

Scope Chain Scope Chain

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.