Skip to content

Instantly share code, notes, and snippets.

@kwhinnery
Last active December 14, 2015 08:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwhinnery/5059196 to your computer and use it in GitHub Desktop.
Save kwhinnery/5059196 to your computer and use it in GitHub Desktop.
var oldThis = this;
// If the Ti object were definied in JS like this...
var Ti = {
UI: {
createView: function(args) {
return new Ti.UI.View(args);
},
View: function(args) {
if (!(this instanceof arguments.callee)) {
return new arguments.callee(args);
}
// work with "this"...
}
}
};
//Prototype behavior remains intact...
Ti.UI.View.prototype.myStuff = 'myStuff';
//...and all these are valid:
var v1 = Ti.UI.createView({ backgroundColor:'#ff0000' });
var v2 = Ti.UI.View({ backgroundColor:'#ff0000' });
var v3 = new Ti.UI.View({ backgroundColor:'#ff0000' });
// new bug goes away....
console.log(v2.myStuff);
console.log(oldThis.myStuff);
@jhaynie
Copy link

jhaynie commented Feb 28, 2013

We could probably remap the API and do this automagically in the compiler

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