项目原始demo,不改动
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
此仓库已存档。您可以查看文件和克隆,但不能推送或创建工单/合并请求。
 
 
 
 

35 行
735 B

  1. module.exports = Stream;
  2. var Parser = require("./WritableStream.js");
  3. function Stream(options){
  4. Parser.call(this, new Cbs(this), options);
  5. }
  6. require("util").inherits(Stream, Parser);
  7. Stream.prototype.readable = true;
  8. function Cbs(scope){
  9. this.scope = scope;
  10. }
  11. var EVENTS = require("../").EVENTS;
  12. Object.keys(EVENTS).forEach(function(name){
  13. if(EVENTS[name] === 0){
  14. Cbs.prototype["on" + name] = function(){
  15. this.scope.emit(name);
  16. };
  17. } else if(EVENTS[name] === 1){
  18. Cbs.prototype["on" + name] = function(a){
  19. this.scope.emit(name, a);
  20. };
  21. } else if(EVENTS[name] === 2){
  22. Cbs.prototype["on" + name] = function(a, b){
  23. this.scope.emit(name, a, b);
  24. };
  25. } else {
  26. throw Error("wrong number of arguments!");
  27. }
  28. });