Chciałbym zastąpić console.log i wywołać to na mojej nowej funkcji.Javascript - Zastąp konsolę.log i zachowaj starą funkcję
próbuję coś takiego, ale pojawia Uncaught TypeError: Illegal invocation
:
console.log = function() {
this.apply(window, arguments);
}.bind(console.log);
console.log('as');
To jest mój cel:
console.error(exception);
należy zrobić:
console.error = function() {
if (typeof exception.stack !== 'undefined') {
console.error(exception.stack);
} else {
console.error.apply(windows, arguments);
}
}.bind(console.error);
console.error('as');
console.error({stack: 'my stack....'});
EDIT: Właściwie, to działa w firefox i nie w Chrome ... To błąd w Chrome : https://code.google.com/p/chromium/issues/detail?id=167911
Trudno powiedzieć, co jest twoim celem. Czy chcesz wywołać inną funkcję po wywołaniu 'console.log', a także wywołanie oryginalnego' console.log'? – DCoder
Poddałem edycji mój cel. – Charles