Last active
November 5, 2015 17:15
-
-
Save FokkeZB/08165210d279766ef67c to your computer and use it in GitHub Desktop.
Checking for Titanium API 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
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')); |
Looks like that as an expression (or part of one) it returns undefined
, but when passed around (assignment, or function invocation) is null
.
I feel stupid. _proto__
with one _
…
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
I guess as long as you know you have an object and need to test if it's not a Ti one... the code as I have it now works ok ;)