Skip to content

Instantly share code, notes, and snippets.

@frostney
Created December 20, 2013 22:14
Show Gist options
  • Save frostney/8062502 to your computer and use it in GitHub Desktop.
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
// 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']);
@pichfl
Copy link

pichfl commented Dec 21, 2013

Deleted my previous comment, but I like the concept. Not quite accurate though. See http://nshipster.com/nil/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment