I'm trying to understand at what point a member function of an object becomes associated with an instance of an object. In the following example
function F() { this.foo = 'foo'; }; var f = new F(); f.test = function() { alert(this.foo); }; var c = f.test; f.test(); (f.test)(); var d; (d = f.test)(); c();
- "foo", "foo", undefined, undefined(as expected). If we look at the AST for the last 4 lines, it looks like this and is the same MemberExpression argument for direct call and destination + call
"foo"
undefined
{ "type": "MemberExpression", "computed": false, "object": { "type": "Identifier", "name": "f" }, "property": { "type": "Identifier", "name": "test" } }
, , (f.test)() - MemberExpression + CallExpression, MemberCallEcpression ( - )? f.foo ?
(f.test)()
f.foo
, / . , , , , . , , , , .
edit β RobG , , . , , , , . ( ) , - ., [ ] =. , , , < GetValue. , . [], "this . , , " ", . = () , " ", .
( )
.
[ ]
=
GetValue
[]
this
, .
Source: https://habr.com/ru/post/1659488/More articles:How to kill the whole subprocess created with pthread_create after the thread was canceled? - cHow to pre-declare a typedef class in C ++ - c ++Understanding the parameter βIβ in the context of the implementation of signs - traitsPhpStorm static method termination - phpHow to combine a 2D array into a 1D array? - javaJVM monitoring in Stackdriver in Google Container Engine (Kubernetes) - javaConvert data from F77 to F90 - fortranHow to disable cascading deletion in Entity Framework Core 1.0 RTM - c #Oblique properties applied to a paragraph - htmlSign up for changes to the baby route in the wizard / part example in Angular 2 - angularAll Articles