Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Bind custom function to the all Function objects Date: Sat, 14 Jun 2014 01:57:13 +0200 Organization: PointedEars Software (PES) Lines: 108 Message-ID: <1464959.oZ30Yp1K6V@PointedEars.de> References: <98e91$539b0b89$6def49ce$21580@nntpswitch.blueworldhosting.com> <1649322.pjBWu2vbqe@PointedEars.de> <94a15$539b16e4$6def49ce$21821@nntpswitch.blueworldhosting.com> <2459085.3y454gxjXg@PointedEars.de> <1e6b6$539b6200$6def49ce$25031@nntpswitch.blueworldhosting.com> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1402703839 4622 eJwNyskRACAIBLCWQGCFcji0/xL0m4kJGL0VBrVrl3hRB9LXnPJsyo/KFrVlznhXtjAWIiR+fiHkEPg= (13 Jun 2014 23:57:19 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Fri, 13 Jun 2014 23:57:19 +0000 (UTC) User-Agent: KNode/4.12.4 X-User-ID: eJwFwQkBwDAIA0BLawK0yOH1L2F3SjtWV0xNdHUtNpqDcoYP8nzjhBTaO0B5TKrgvUqflea5YG5cRWdJ/mJhFec= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg== X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. 2014-06-13 19:01, Thomas 'PointedEars' Lahn wrote: >> Cezary Tomczyk wrote: >>> 2014-06-13 16:56, Thomas 'PointedEars' Lahn wrote: >>>> Cezary Tomczyk wrote: >>>>> I am looking for a solution where I can bind custom function to the >>>>> all Function objects. Whenever any function/method will be called I'd >>>>> like to call my custom function. I am going to use it only for >>>>> testing/debugging. Doesn't have to be cross-browser. >>>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >>>> What does this mean? >>> >>> This means that if one browser support required functionality then I'll >>> use that specified browser in my case. >> >> Learn to think in terms of versions of implementations, not browsers. > > Agreed. However before I start think in terms of versions of > implementations I need to figure out those implementations So you should ask “Which implementation X supports feature Y?” and then “Which browser Z supports implementation X?”, and not “Which browser Z supports feature Y?” > Based on your previous answer there is nothing I can find and use in my > case (below details). Do not jump to conclusions. Your case was not at all clear. > Let me rephrase it. When I run the web application in the browser > environment then I'd like to check how many times every > functions/methods are called. The simplest way is to add console.count > (https://developer.mozilla.org/en-US/docs/Web/API/console.count) to > every function/method. Thanks, I did not know of that method. > However, I think that in reality it's not possible to do that because > then changes needs to be done everywhere in the code. So, I thought that > it would be better to "wrap" every function/method globally (not sure if > I described it correctly) so that every call of function/method in web > application first will call custom function before and put information's > from console.count. In that way I could measure how many times every > function/method is called. That's my goal. It is possible to wrap all *your* functions (that you *know*) simply by replacing them (I do something similar in jsx.dom.addEventListener() in order to emulate EventTarget::addEventListener() when unavailable): var myFunction = function () { console.log("myFunction"); }; /** * Adds a call counter to a function. * * NOTE: Must pass object reference and property name for a general * solution because there is no call-by-reference * * @param {Object} obj * @param {String} propName * @return {Function} * Decorated function */ function addCounter (obj, propName) { var original_function = obj[propName]; if (typeof original_function != "function") { throw new TypeError( "addCounter: obj[propName] must refer to a function"); } var decorated = function () { console.count("myFunction"); original_function.apply(this, arguments); }; obj[propName] = decorated; return decorated; } /* * Example: in global context; cannot generally decorate local functions */ addCounter(this, "myFunction"); However, as I have (re)discovered today thanks to your posting, it is easier to use the Firebug profiler. Go to the “Console” tab, select “Profile”, and select “Profile” again when you are done. The second column of the profile shows the number of times each function/method was called. However, note that you will be only profiling the behavior of your code with Mozilla JavaScript. I could not find a similar feature in Iceweasel 30’s built-in Web Developer Tools or in Chrome Developer Tools in Chromium 34. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not Cc: me. / Bitte keine Kopien per E-Mail.