我有一个简单的例子:
function File(name) {
this.name = name
this.text = null
}
File.prototype = {
read: function() {
fs.readFile(this.name, function (err, data) {
}
},
getContent: function() {
return this.text
}
}
var myfile = new File('my_file')
watch.createMonitor('my_file_dir', function (monitor) {
monitor.files['my_file']
monitor.on("change", function (f, stat) {
myfile.read()
}
})
main program....:
myfile.getContent() ...
我想在 this.text 变量中添加文件内容。怎么做 ?