Skip to content

Instantly share code, notes, and snippets.

@rblalock
Created November 2, 2011 15:15
Show Gist options
  • Save rblalock/1333884 to your computer and use it in GitHub Desktop.
Save rblalock/1333884 to your computer and use it in GitHub Desktop.
Wrapping TiUI Objects
// 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);
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();
};
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;
};
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');
};
@rblalock
Copy link
Author

rblalock commented Nov 2, 2011

Nice addition from @iskugor - http://pastie.org/2799391

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