Created
November 2, 2011 15:15
-
-
Save rblalock/1333884 to your computer and use it in GitHub Desktop.
Wrapping TiUI Objects
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
// Prototype version: | |
// Ti.include('prototype.js'); | |
// Module version: | |
// Ti.include('module.js'); | |
// Factory version: | |
Ti.include('factory.js'); | |
var win = Ti.UI.createWindow({ | |
title: 'Extension Tests', | |
backgroundColor: '#eee' | |
}); | |
win.open(); | |
// Factory Version | |
var myView = View({ | |
height: 50, | |
backgroundColor: '#ccc' | |
}); | |
// 'new' keyword needed for prototype and module versions | |
var myView = new View({ | |
height: 50, | |
backgroundColor: '#ccc' | |
}); | |
myView.add( | |
Ti.UI.createButton({ title: 'Click me' }) | |
); | |
// Add stuff to your new 'view' | |
myView.foo = {}; | |
myView.foo.bar = 'hello'; | |
myView.foo.bar = 'goodbye'; | |
alert(myView.foo.bar); | |
myView.coolbeans(); | |
win.add(myView.Element); |
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 View = function(options) { | |
function factory() { | |
var obj = {}; | |
obj.Element = Ti.UI.createView(options); | |
obj.add = function(TiObject) { | |
obj.Element.add(TiObject); | |
}; | |
obj.coolbeans = function() { | |
alert('Cool Beans'); | |
}; | |
return obj; | |
}; | |
return new factory(); | |
}; |
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
function View(options) { | |
var api = {}; | |
api.Element = Ti.UI.createView(options); | |
api.add = function(TiObject) { | |
api.Element.add(TiObject); | |
}; | |
api.coolbeans = function() { | |
alert('Cool Beans'); | |
}; | |
return api; | |
}; |
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
function View(options) { | |
this.Element = Ti.UI.createView(options); | |
} | |
View.prototype.add = function(TiObject) { | |
this.Element.add(TiObject); | |
}; | |
View.prototype.coolbeans = function() { | |
alert('Cool Beans'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice addition from @iskugor - http://pastie.org/2799391