Skip to content

Instantly share code, notes, and snippets.

@brentonhouse
Forked from rblalock/app.js
Created April 25, 2014 17:56
Show Gist options
  • Save brentonhouse/11297957 to your computer and use it in GitHub Desktop.
Save brentonhouse/11297957 to your computer and use it in GitHub Desktop.
// 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');
};
@brentonhouse
Copy link
Author

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

function Window(options) {
this.Element = Ti.UI.createWindow(options);
}

Window.prototype.add = function(TiWrapper) {
if (TiWrapper && TiWrapper.Element) {
this.Element.add(TiWrapper.Element);
}
};

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