Model.js 文件具有以下条目
exports.update = function(tag,view,date){
{
.....
....
}
并调用该函数,例如
update('test','1213','11/10/2014')
它抛出以下错误,
update('test','1213','11/10/2014')
^
ReferenceError: update is not defined
我可以从不同的文件调用更新模块,不会出现任何类似这样的错误
var model = require('./Model');
model.update('test','1213','2001/1/23')
问题是如何从同一个 js (Model.js ) 文件调用 Update 方法
在 model.js 中
exports.update = function update(tag, view, date) { ... }
exports.update('red', 'colors', new Date())
如果您经常调用该方法(例如在循环中),还可以考虑声明局部变量
var update = exports.update = function update(tag, view, date) { ... }
update('red', 'colors', new Date())
内部 foo.js
var update = require('./model').update
update('yellow', 'colors', new Date())
从问题本身来看,尚不清楚更新方法的作用以及哪些数据,因此如果您提供真实的代码,答案可能会有所调整。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)