Try:
function helloWorld(age, name, callback) {
console.log('age ' + age);
console.log('name ' + name);
process.nextTick(function(){
callback(age);
});
};
helloWorld(15, 'Hello', function(age) {
console.log('callback function helloworld - '+age);
});
console.log('Hello world');
Also, why process.nexTick here at all? You can just call the callback
without nexTick.
On Fri, Apr 27, 2012 at 8:51 PM, Arun Avanathan <[email protected]>wrote:
> hello.js :
>
> function helloWorld(age, name, callback) {
> console.log('age ' + age);
> console.log('name ' + name);
> process.nextTick(callback(age));
> };
>
> helloWorld(15, 'Hello', function(age) {
> console.log('callback function helloworld - '+age);
> });
> console.log('Hello world');
>
>
> When I run node hello.js I am getting this output:
>
> age 15
> name Hello
> callback function helloworld - 15
> Hello world
>
> node.js:201
> throw e; // process.nextTick error, or 'error' event on first
> tick
> ^
> TypeError: Property '0' of object is not a function
> at EventEmitter._tickCallback (node.js:192:40)
>
> Questions :
>
> 1. Why the error? What am I doing wrong?
> 2. I am expecting it to print
>
> age 15
> name Hello
> Hello world
> callback function helloworld - 15
>
> the callback function should log after "Hello World", isn't it?
>
> Thanks
> Aru
>
> --
> 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 [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
--
--
Marak Squires
Co-founder and Chief Evangelist
Nodejitsu, Inc.
[email protected]
--
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en