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