Javascript 更换'有什么明显的好处吗;一次性使用';具有属性或对象的函数

Javascript 更换'有什么明显的好处吗;一次性使用';具有属性或对象的函数,javascript,performance,garbage-collection,Javascript,Performance,Garbage Collection,换句话说,使用这样的代码: <script> window['object'] = function(arg) { var myvar = 1; this.object = {}; //assign new properties and do more stuff this.object.x = arg?arg+1:myvar;//just one example for the context } //run function once and overwrite

换句话说,使用这样的代码:

<script>
window['object'] = function(arg) {
  var myvar = 1;
  this.object = {};
  //assign new properties and do more stuff 
  this.object.x = arg?arg+1:myvar;//just one example for the context
}
//run function once and overwrite it with object
object(1);
</script>

窗口['object']=函数(arg){
var-myvar=1;
this.object={};
//分配新属性并执行更多操作
this.object.x=arg?arg+1:myvar;//仅举一个上下文示例
}
//运行函数一次并用对象覆盖它
对象(1);
  • 函数本身是否被垃圾收集
  • 它是否会导致对象重用场景,其本身会降低创建新对象的成本

  • 当然,这是假设函数需要包含局部变量和/或参数依赖项,证明有一个实际的函数可以首先设置对象。

    我将用Vyacheslav Egorov给出的答案来结束这个问题, 一个疯狂的俄罗斯编译工程师,为谷歌工作,这是不言自明的

    没有真正的性能优势(好的,单个属性可以重用,但仅此而已)