Created
December 20, 2013 22:14
-
-
Save frostney/8062502 to your computer and use it in GitHub Desktop.
Annoying your coworkers with masking JavaScript functions to look like Objective-C calls
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
// Yeah, what is null? Let's make it nil | |
var nil = null; | |
var objc_call = function(magic) { | |
if (magic === nil) { | |
return nil; | |
} | |
var args = Array.prototype.slice.call(arguments, 1); | |
// TODO: Object traversal would be possible, but that's just taking the joke too far | |
return (args.length > 0) ? magic[0][magic[1]].apply(magic[0], args) : magic[0][magic[1]]; | |
}; | |
// Redefining this | |
var self = this; | |
var stringObj = objc_call([self, 'String']); | |
var docId = objc_call([document, 'getElementById', 'test']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Deleted my previous comment, but I like the concept. Not quite accurate though. See http://nshipster.com/nil/