I want to modify console.log
so that it saves everything that the application outputs to the mand line using console.log
.
I have tried
var log = console.log;
console.log = function () {
// fs.appendFile('log.txt ..
log.apply(log, arguments);
}
But it gives me the error
Illegal invocation
I want to modify console.log
so that it saves everything that the application outputs to the mand line using console.log
.
I have tried
var log = console.log;
console.log = function () {
// fs.appendFile('log.txt ..
log.apply(log, arguments);
}
But it gives me the error
Illegal invocation
Share
Improve this question
asked Jun 11, 2015 at 18:44
afonso-botafonso-bot
351 silver badge4 bronze badges
1 Answer
Reset to default 10The first arguments to apply
is what this
will refer to. To mimic a call to console.log()
, you have to pass console
, not the function itself:
var log = console.log;
log.apply(console, arguments);
// log.apply(this, arguments); would work as well
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742289379a4415907.html
评论列表(0条)