Skip to content

Instantly share code, notes, and snippets.

@FokkeZB
Last active November 5, 2015 17:15
Show Gist options
  • Save FokkeZB/08165210d279766ef67c to your computer and use it in GitHub Desktop.
Save FokkeZB/08165210d279766ef67c to your computer and use it in GitHub Desktop.
Checking for Titanium API objects
var jsObject = {
foo: 'bar'
};
var tiObject = Ti.UI.create2DMatrix();
function isJsObject(obj) {
return typeof obj.__proto__ !== 'undefined';
}
console.log('jsObject: ' + (isJsObject(jsObject) ? 'yes' : 'no'));
console.log('tiObject: ' + (isJsObject(tiObject) ? 'yes' : 'no'));
@yuchi
Copy link

yuchi commented Sep 22, 2014

Looks like that as an expression (or part of one) it returns undefined, but when passed around (assignment, or function invocation) is null.

@yuchi
Copy link

yuchi commented Sep 22, 2014

I feel stupid. _proto__ with one _

@yuchi
Copy link

yuchi commented Sep 22, 2014

function isJSObject(o) { return !!(o && o.__proto__ !== undefined); };

works flawlessy…

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