上のthisと下のthisに違うものが入るかと思ったが、両方とも同じグローバルオブジェクトがはいるんだな forEachの仕様をよく理解してなかったわ 02282212012/10/02(火) 19:41:47.18ID:??? var lazy = require("lazy");
var fs = require("fs");
function foo(){ var collection = {} this.Add = function(line){ //lineの内容に応じた処理を行う //collectionに追加 console.log(line); } function GetRoomList(callback){ var stream = fs.createReadStream("roomlist.txt"); new lazy(stream) .lines .forEach(function(line){ this.Add(line); }); } GetRoomList(); }
$test = new foo(); 文法エラーを修正したが、こんなエラーが出る 0229nobodyさん2012/10/02(火) 19:48:55.73ID:??? TypeError: Object #<Object> has no method 'Add' at C:\Users\xxx\Documents\WebChat\test.js:17:9 at EventEmitter.self.forEach (C:\Users\xxx\Documents\WebChat\node_modules \lazy\lazy.js:62:13) at EventEmitter.<anonymous> (C:\Users\xxx\Documents\WebChat\node_modules\ lazy\lazy.js:46:19) at EventEmitter.emit (events.js:93:17) at self.bucket.yield (C:\Users\xxx\Documents\WebChat\node_modules\lazy\la zy.js:152:18) at Function.<anonymous> (C:\Users\xxx\Documents\WebChat\node_modules\lazy \lazy.js:186:21) at self.bucket (C:\Users\rirufa\Documents\WebChat\node_modules\lazy\lazy.js: 158:21) at EventEmitter.emit (events.js:93:17) at ReadStream._emitData (fs.js:1365:10) at afterRead (fs.js:1347:10) 0230nobodyさん2012/10/02(火) 19:55:27.08ID:??? fooは普通の関数じゃなくてコンストラクターなのかw それだと上のthisと下のthisは違ってしまうからうごかんわw