3
我目前正在使用Node來製作我的第一個機器人,但我對於如何將其變爲現實感到有點困惑。問題是,什麼是我應該使用這種東西的模式的最佳模式和名稱?Node/JavaScript中應該使用什麼模式來製作監聽器?
基本上,一個人可以聽一個主題和說話人。
var test = person("ask_name","hallo person you are special");
console.log(test); // should return thanks!
var test = person("ask_name","hallo person you are dumb as the bird");
console.log(test); // should return i hate you!
function person(ability, body) {
console.log(ability,body);
var ability_name = "ability_" + ability;
console.log(ability_name,typeof ability_name); // ignore all of this, trying something
if (typeof ability_name) {};
// ability list array
var ability = [];
// Search for ability
// not done
var say_bad = function() {
this.listen_subject = 'ask_name';
this.listen_body = 'you are dumb';
return "i hate you!"
}
var say_good = function() {
this.listen_subject = 'ask_name';
this.listen_body = 'you are special';
return "thanks!"
}
}
對不起,沒有完成代碼,但這是我可以走的最遠的地方。
可以發射和偵聽事件。真正簡單的API:http://nodejs.org/api/events.html – danneu