在node.js中更改对象原型的位置? [英] Where to change objects prototypes in node.js?

查看:126
本文介绍了在node.js中更改对象原型的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加或覆盖Object,Function和Array的一些标准方法(例如,如这个答案)。我应该如何在一个模块中执行所有修补程序,以便影响我的所有其他模块?

I want to add or override some standard methods of Object, Function and Array (e.g., like suggested in this answer) in node.js application. How should I do all the "patches" in just one module so that it affects all my other modules?

如果我在一个模块中执行它是否足够只是 require 'd或者它不起作用,因为这两个模块有不同的全局命名空间,所以它们有不同的对象?...或者我应该在<$之后运行一些初始化函数c $ c> require 使所有这些补丁也在这个模块中工作?

Will it be enough if I do it in a module that is just require'd or it won't work because the two modules have different global namespaces so they have different Object?... Or should I run some initialisation function after require that makes all these "patches" working in this module too?

推荐答案

加载的每个文件共享相同的原始对象,如Object,Array等,除非在不同的vm上下文中运行,因此在初始化时要求文件一次将在各处进行更改。

Each file loaded shares the same primordial objects like Object, Array, etc, unless run in a different vm Context, so requiring the file once in your initialization will make the changes everywhere.

这篇关于在node.js中更改对象原型的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆