You are invoking fileCallback inside the call to fs.readFile, you just want to
provide the function referencer instead.
var fs = require('fs');
fs.readFile(process.argv[2], fileCallback);
function fileCallback(err, file) {
console.log(file.toString().split('\n').length - 1);
}
--
Paul Spencer
Sent with Airmail
From: Liam Ryan Liam Ryan
Reply: [email protected] [email protected]
Date: January 23, 2014 at 6:10:34 AM
To: [email protected] [email protected]
Subject: [nodejs] Re: Tidying up callback declarations
Thanks, declaring the expression before the call worked perfectly, I'm still
struggling with the function declaration though -
var fs = require("fs");
fs.readFile( process.argv[2], fileCallback(err, file) );
function fileCallback(err, file) {
console.log(file.toString().split("\n").length - 1);
};
On Wednesday, January 22, 2014 10:23:49 PM UTC, mks wrote:
Your callback is a function expression, hence doesn't get hoisted.
Write it as a function declaration or move the function expression before the
readdir call.
On Wednesday, January 22, 2014 7:19:14 PM UTC+1, Liam Ryan wrote:
Hi All,
Probably a stupid question but I wanted to make my code for filteredLS easier
to read by doing something like -
var fs = require("fs);
fs.readdir(process.argv[2], callback);
var callback = function( err, files) {
....
}
However this doesn't seem to work, is it my syntax or will this just not work
for node?
--
--
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
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
--
--
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
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.