What is better for static messages in Typescript? (performance and memory wise) -


what better static messages in typescript? (performance , memory wise) variables or methods? let's need hundreds of them. msg1 or msg2()

import {messages} './messages';  export class messagesen implements messages {   readonly msg1 = 'message one';   msg2(): string {    return 'hello second!';  } 

}

from point of encapsulation, fields (aka msg1) must not visible client, need let client work code methods manipulate data of objects , change objects state.

from point of performance accessing field bit faster, because goes , tries find field , returns it. method same thing , goes , call it: 1 operation. in cases functions doesn't change it's context, inlined, allows them accessed faster. if change in function after code execution, compiler can't not optimize , work slower field access.

from point of memory wise, method take more memory stack field

you can see jsperf property access more faster method access.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -