Some basics of JavaScript

Source: Internet
Author: User

When the addresses of the two variables copied are not at the same time they are not equal as shown in the following code

function GetFunction (value) {  return function (value) {        return value;    }  } var a=getfunction (),      b=getfunction (),      c=getfunction (); Console.log (a==b)  //false

When you define a standalone function, the This keyword is bound to the global namespace. As a direct result, when creating an intrinsic function within a method, the This keyword of the intrinsic function is bound to the global namespace instead of being bound to the method, and in order to solve this problem you can simply assign the package method this keyword to a middle variable named that. The code is as follows

obj = {};obj.method = function () {  var = this;  This.counter = 0;  var count = function () {       That.counter + = 1;       Console.log (That.counter);      }     Count ();    Call the Count function    1     count ();  Call the Count function    2     console.log (this.counter);   So this is 2.}      Obj.methos ();      1 2 2

In JavaScript to use a private method or property it is necessary to use closures

function TimeMachine () {    //Private member    var destination = "A, b";    Public member    this.getdestination = function () {        return destination;    }} var DeLorean = new TimeMachine (); Console.log (Delorean.getdestination ());  A,bconsole.log (deloreon.destination); Undifine

  

  

Some basics of JavaScript

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.