Last active
December 14, 2015 08:38
-
-
Save kwhinnery/5059196 to your computer and use it in GitHub Desktop.
This file contains 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
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We could probably remap the API and do this automagically in the compiler