function myClass() { //lots and lots of vars and code here. this.bar = function() { //do something with the numerous enclosed myClass vars } this.foo = function() { alert('Hello'); //don't do anything with the enclosed variables. } }
Each instance of myClass gets its own copy of bar and foo, so prototype methods use less memory. However, I would like to learn more about using internal memory methods.
It seems obvious to me that (1) below should be true. Do you agree?
Now (2) the question arises that I am really worried about.
, . , - , .
, , bar, foo " " . , . , , " " , - .
, , JavaScript. .
, .
:
10.4.3 , , F, thisArg, :, ThisBinding thisArg.thisArg null undefined, ThisBinding .(thisArg) , ThisBinding ToObject (thisArg).Else ThisBinding Arg.localEnv NewDeclarativeEnvironment [[]] F .LexicalEnvironment localEnv.localEnv.
10.4.3 , , F, thisArg, :
NewDeclarativeEnvironment.
NewDeclarativeEnvironment
10.2.2.2 NewDeclarativeEnvironment (E) NewDeclarativeEnvironment , null E :env .envRec - , .envs envRec.env E.env.
10.2.2.2 NewDeclarativeEnvironment (E) NewDeclarativeEnvironment , null E :
E, [[Scope]] Object
[[Scope]]
13.2 . FormalParameterList, FunctionBody, , , Boolean flag Strict, Function :ECMAScript F ., [[Get]], F, 8.12.[[Class]] F "Function".[[Prototype]] F , 15.3.3.1.[[Get]] F, 15.3.5.4.[[Call]] F, 13.2.1.[[Construct]] F, 13.2.2.[[HasInstance]] F, 15.3.5.3.[[]] F Scope., .
13.2 . FormalParameterList, FunctionBody, , , Boolean flag Strict, Function :
, , . . , , "" .
, , .
. () , . , , . . , Declaration FunctionDeclarations, .
Lexical Environment
, . , . , , , V8 (chrome JS engine) Spidermonkey (Firefox) JScript (IE) .....
( , GHC ), ( ) , "" (bar), , , JS MyClass, , , this.bar, , foo , , MyClass, .
this.bar
foo
MyClass
, JS eval, , eval, , JS .
eval
, , , : -)
Spidermonkey: - . , .
V8: - , " ". " ", , , , V8 GC .
Unfortunately, these meager links are all I can find. A direct analysis of the engine source code is likely to require the addition of more meaningful input.
So, yes, different engines implement different optimization strategies when they can.
Source: https://habr.com/ru/post/1791762/More articles:need shell script to change comma delimiter to pipe delimeter - shellFacing Issues When Using Spring Security in GAE - springDynamic string array structure in C - chttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1791760/what-are-efficient-ways-to-enhance-the-security-of-md5-hashes&usg=ALkJrhjkuU1vbMFMi5Tc-yF-zAAsOa6mYwПроверка разрешений на основе ролей для всех действий централизованным или чистым способом в приложениях .Net - c#How can I sort my products by price and name? - javaHow to switch 2 divs at the click of a button? - jqueryDynamic namespace module template - javascriptHow can I use memcache Google App Engine with Quercus? - javaC ++ random int function - c ++All Articles