English 中文(简体)
JSJ: 请求代码片断解释
原标题:Node JS : Requesting for code snippet explanation
  • 时间:2012-05-24 13:58:04
  •  标签:
  • node.js

我只是想知道,什么是目的,

function MyStream() {
    events.EventEmitter.call(this);
}

在以下一组代码 取自Nodejs.org Docs部分,

var util = require("util");
var events = require("events");

function MyStream() {
    events.EventEmitter.call(this);
}

util.inherits(MyStream, events.EventEmitter);

MyStream.prototype.write = function(data) {
    this.emit("data", data);
}

var stream = new MyStream();

console.log(stream instanceof events.EventEmitter); // true
console.log(MyStream.super_ === events.EventEmitter); // true

stream.on("data", function(data) {
    console.log( Received data: "  + data +  " );
})
stream.write("It works!"); // Received data: "It works!"

请解释。

最佳回答

这不是第一次问这个问题:https://groups.google.com/forum/#!topic/nodejs/ab_Xih1L5R8/discussion

布莱德利·梅克的引文:

使用 Epid Eminit 。 呼叫一个对象将会设置一个事件 Eminit 的试例方法/ 属性( 不是继承的) 。 它的目的与 Java 或 C# 中的 base (...) 相似, 但它在 Java 或 base (...) 类似, 但没有隐含在 Java 描述中 。 因此, 我们必须手工称呼它自己 。 关于 util. inherits 的谈话, 这将让 MyStream 函数从另一个原型函数继承, 这样一例工程( 旁注: javastrimt 仅允许单项继承) 。 由于新操作员是如何工作的, 如果我们将此变量设置在事件 Empit 的示例中, 并调用事件 Eminit 。 请用它来显示所有意图和目的, 如 事件 Emint sbuiltor 正在被调用到我们的 MyStream 对象 。

问题回答

暂无回答




相关问题
How to make Sequelize use singular table names

I have an model called User but Sequelize looks for the table USERS whenever I am trying to save in the DB. Does anyone know how to set Sequelize to use singular table names? Thanks.

What is Node.js? [closed]

I don t fully get what Node.js is all about. Maybe it s because I am mainly a web based business application developer. What is it and what is the use of it? My understanding so far is that: The ...

Clientside going serverside with node.js

I`ve been looking for a serverside language for some time, and python got my attention somewhat. But as I already know and love javascript, I now want learn to code on the server with js and node.js. ...

Can I use jQuery with Node.js?

Is it possible to use jQuery selectors/DOM manipulation on the server-side using Node.js?

How do I escape a string for a shell command in node?

In nodejs, the only way to execute external commands is via sys.exec(cmd). I d like to call an external command and give it data via stdin. In nodejs there does yet not appear to be a way to open a ...

热门标签