in your john.js file:

    var Client = require("./client");

Client is a function.  You then try to inherit from said function

   Object.create(Client, ...






On Tue, Jun 5, 2012 at 11:15 AM, howdoicodethis <howdoicodet...@gmail.com>wrote:

> Hi everyone.  Glad to be here.
>
> I'm still struggling with some aspects of nodejs, and perhaps even
> javascript in general, so thank you everyone for your patience in advance.
>
> I've been able to do this in one file, but when I throw the require() in
> it, it stops working.
> I understand there's a util.inherits() that also works with inheritance,
> but I'd like to manually set the enumerable and writable properties myself.
>
>
> Here's a single file version that works:
>
> var sys = require("util");
>
> // client object
> var Client = {
>   ip: null,
>   stream : null,
>   state: "Connecting",
>   eyes: 2,
>   legs: 4,
>   name: null,
>   toString: function () {
>     return this.name + " with " +
>       this.eyes + " eyes and " +
>       this.legs + " legs, " + this.state + ".";
>   }
> }
>
> // John inherits Client object
> var john = Object.create(Client, {
>   name: {value: "John", writable: true},
>   state :  {value: "working", writable: true}
> });
>
> sys.puts(john);
> // John with 2 eyes and 4 legs, working.
> -----------------------
> Here's when it stops working
>
> ---- client.js ----
> module.exports = function (instream, inip){
> return  {
>  ip: null,
>   stream : null,
>   state: "Connecting",
>   eyes: 2,
>   legs: 4,
>   name: null,
>   toString: function () {
>     return this.name + " with " +
>       this.eyes + " eyes and " +
>       this.legs + " legs, " + this.state + ".";
>   },
> };
> };
>
> ---- john.js ----
> var Client = require("./client");
> module.exports = function (inname, instate){
> return Object.create(Client, {
>   state : {value: inname, enumerable: false, writable: true},
>   name: {value: instate, enumerable: true, writable: true},
> });
> };
>
> ---- index.js ----
> var sys = require("util");
> var Client = require("./client")("stream","168.192.0.1");
> sys.puts(Client);
> // null with 2 eyes and 4 legs, Connecting.
>
> var john = require("./john")("John","Sleeping");
> sys.puts(john); // ERROR: Function.prototype.toString() is not generic,
> ie. inheritance failed.
> sys.puts(sys.inspect(john)); // { name: 'Sleeping' } for some reason? Is
> it because name was declared as the second line of that object?
> sys.puts(sys.inspect(john,true)); // { name: 'Sleeping', [state]: 'John' }
>
> --------------------------------------
> What am I doing wrong?  Am I missing some conceptual change when I split
> them up into different files and link them together using require() ?
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nodejs@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to