[nodejs] I can't understand why this happen, it's a simple code

2012-07-30 Thread 软刀
# a.js : #! /usr/bin/env node // coding: utf-8 // author: ruandao(ljy080...@gmail.com) var app = exports; app.yaha = 'jjj'; app.yahajk = 'eklj'; app.echo = function(){ console.log(this.yaha); }; and I run in node: yan@cpu:~$ node a=require('./a'); { yaha: 'jjj', yahajk: 'eklj', echo:

Re: [nodejs] I can't understand why this happen, it's a simple code

2012-07-30 Thread José F . Romaniello
You can use exports which is an empty object as: var app = exports; app.yaha = 'jjj'; app.yahajk = 'eklj'; app.echo = function(){ console.log(this.yaha); }; or you can use assign your thing to module.exports: var app = {}; app.yaha = 'jjj'; app.yahajk = 'eklj'; app.echo = function(){

Re: [nodejs] I can't understand why this happen, it's a simple code

2012-07-30 Thread Roly Fentanes
That's how javascript works. If you assign an object `a` to `b`, you're assigning the reference. You are not making a copy. If you modify one, the change will reflect on both since they both point to the same object. On Sunday, July 29, 2012 7:39:29 PM UTC-7, 软刀 wrote: # a.js : #!

Re: [nodejs] I can't understand why this happen, it's a simple code

2012-07-30 Thread Tim Caswell
http://howtonode.org/object-graphs - basic explanation about object references http://dmitrysoshnikov.com/ecmascript/javascript-the-core/ - more correct, but harder to understand explanation. On Mon, Jul 30, 2012 at 9:10 AM, Roly Fentanes roly...@gmail.com wrote: That's how javascript works. If

Re: [nodejs] I can't understand why this happen, it's a simple code

2012-07-30 Thread Thom Blake
`exports` is simply a variable containing a reference to `module.exports`. `module.exports` is an empty object to start, so you can start assigning stuff to its properties right away. So when you have `var app = exports`, you're using `app` as a reference to the object assigned to

Re: [nodejs] I can't understand why this happen, it's a simple code

2012-07-30 Thread 软刀
thanks you I got it. -- 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