Display where function is called from not where it is defined console javascript -


I'm a lazy developer ... I like to make shortcuts, so I get console.info to c

/*core_functions.js*/ / * ============================ == ==================== Bind C to be alert on the mobile console in the desktop.log ================ ================================== * / window.c = False; If (type of console === "object" & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; ;; SP.isMobile) {c = function (msg) {console.info (msg); }; } And {c = function (msg) {debug}; }; } /*somefile.js*/ c (anObject);

I have been experimenting this for some time and some have always offended me, it displays the file in which the function is defined, from where the function is called :

  core_functions.js: 40 object {stadium name: "stadium 3", pitch: object, lights: object, seats: object, scoreboard: object ...}  

Can I say context where the function is being called from? Or have I been stuck with this little annoyance forever?

You are looking at that line number because it is actually where console.info < / Code>. In a way I can think of avoiding it by calling the actual console method instead of having a proxy with an intermediate function.

It seems that you have to lay an abstract layer to handle your logging using the original login or custom.

In that case, you can try to do something like this:

  var c = (typeof console === 'object')? Console: optional;  

and then use it:

  c.log ('Hello World');  

Thus your optional object may be one of the methods you are considering using, for example:

  var optional = {Log: function () {Window.alert.apply (window, logic); }};  

In this way you will not get your c () function, but I think you will end up with a more flexible solution. By highlighting the same interface in that console you can also add these logging features to any code running in your app (i.e., the third party code using native code console )

  window.console = (typeof window.console === 'object')? Window.console: Optional  

or if you're feeling lazy on that day :)

  window.console = window.console || Optional  

This is not the right technique, but if you are using it, then it may help to be used.

Besides, I have never really been involved in stack overflow, so I am very sorry if I am ignoring any rules or etiquette :)


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -