Search code examples
javascriptgoogle-chromev8v8js

Javascript: Using function properties as "static" variables and optimization


One way to get "static" variables in a function (like the "static" keyword in C) in Javascript is to assign custom properties to the function object itself.

A few years ago, this caused problems with optimization in eg. V8 because when the function object's properties changed, the function had to be re-JIT-ted, etc.

Is this still the case, or is there a reliable way to benchmark this?


Solution

  • V8 developer here. I don't remember that putting properties on function objects has ever caused problems. Do you have a source for that claim? Maybe it's a misunderstanding.

    At any rate, these days you can definitely do that without issues.