Created
October 27, 2010 06:28
-
-
Save fitzgen/648562 to your computer and use it in GitHub Desktop.
Spam or not?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from N!#@R ... <[email protected]> | |
| to [email protected] | |
| date Tue, Oct 26, 2010 at 11:20 PM | |
| subject Need help with Javascript issue | |
| mailed-by gmail.com | |
| signed-by gmail.com | |
| Hello, | |
| I just visited your blog http://fitzgeraldnick.com/weblog/ for some of the javascript related code snippets and it was really cool! I just thought if you could help me with something that I am trying.. | |
| I am trying to implement a Logger function that would log something.... when there is an api call on a given object. For e.g. | |
| mapObj.getLatLong( ); | |
| Assume I have the 'mapObj' which is from some third party API, which offcourse cannot be tampered. What I want to do is, whenever there is an API call on mapObj, I want the 'Logger' to get executed first, and then the actual API call. So, it's like intercepting the actual call. | |
| I managed to iterate on the mapObj and if ( typeof ( obj[i] === 'function' ) ) ... bind to the Logger. I am thinking binding/re-binding would help, but not able to get through it.. | |
| Logger = function( ) { | |
| // logs something - may be arguments, etc... | |
| } | |
| // execute this anonymous func... | |
| // I have the mapObj | |
| ( function( ) { | |
| var _ob = arguments[0]; | |
| for ( var i in ob ) { | |
| if ( typeof ( obj[i] === 'function' ) ) { | |
| // bind to Logger..... | |
| } | |
| } | |
| } ) ( mapObj ) ; | |
| mapObj.getLatLong( ) ; // should execute Logger first, then execute actual call getLatLong .. | |
| Any help would be really appreciated. | |
| Thanks. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment