javascript - How to find if message is already printed to the console -


assume run javascript project in browser , i'm inside specific module, can check whether already message printed console ? i.e. read message console...

for example i'm inside js.file inside function want check if printed hello world in console.

jthanto's answer gave me idea. don't think it's practice, if must, can define own console class:

var myconsole = function(oldconsole) {     // store messages ever logged     this.log = [];     // keep pointer oldconsole     this.oldconsole = oldconsole; }  myconsole.prototype.log = function(args) {     // push message log     this.log.push(array.prototype.join.call(args));     // call oldconsole.log display message on console     if (this.oldconsole)         this.oldconsole.log.apply(this.oldconsole, args); }  // todo: implement other console methods in fashion (apply console api methods) myconsole.prototype.<method> = function(args) {     if (this.oldconsole)         this.oldconsole.<method>.apply(this.oldconsole, args); }  // method check if printed myconsole.prototype.waslogged(message) {     return this.log.indexof(message)!==-1; }  // replace console instance of myconsole, pointing old console console = new myconsole(console); 

save in file , load first (right @ top of tags)

use like:

if (console.waslogged("hello world"))     dostuffz(); 

hope helps. mind it's not tested, should give pointers :)


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -