Static class objects in node. js Inheritance (some bug fixes in the "node. JS Development Walkthrough" book)

Source: Internet
Author: User

Today is a good gas, recently hung up some interview after a slight loss of mood.

God Horse is a cloud, to always do the world second.

No more, you ask me why the mentality has changed. -------are feelings,.

Well, I'm studying node recently.

People ask, you have this level of node ...

hahaha, so sad ....

Don't mention it.

God Horse modular God horse is not much to say, on a module.export and export differences, the latter object of the property belongs to the former, inverse proposition is not established.

and Util.inherits (A, B) This API note that A will only inherit the prototype method of B, not the prototype will inherit. It's not that the data in the prototype is shared, so it's estimated that this function creates a reference.

Well, to get to the point, "node. JS Development Combat Detail" This book is still very open to the novice, but after reading the second chapter, I feel like something is wrong.

The book mentions the Observer pattern, as if there is no special section to say, an example in the after-school combat ... Uh... There is really no observer in the catalogue ... Alas, this is all a small problem.

This static class still finds minor problems:

Here is a base class. Person.js file name.

/* defining the person base class */ module.exports=function() {    this. name= ' person ';      this. sleep=function() {        console.log (' person sleep ');    }     this. eat=function() {        console.log (' person eat ');}    }

Then here is a derived class, Student.js filename

varUtil=require (' Util ');varPerson=require ('./person '));functionStudent () {Person.call ( This);    Util.inherits (Student,person);  This. study=function() {Console.log (' Study person '); }}varperson=NewStudent ();//In fact, the main point is here, the book is so written on the Var person=new person (); Well, obviously not, and if so, what's the student () method? exports.study=person.study;exports.eat=Person.eat;exports.sleep=person.sleep;

Then run the file app.js.

var student =require ('./student '); Student.study (); Student.eat (); Student.sleep ();

Uh.. You're done so soon? Well, see another question again. This update below. Make a mark: 2015-4-13-16-46 (Lost time, relentlessly. Alas

Static class objects in node. js Inheritance (some bug fixes in the "node. JS Development Walkthrough" book)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.