problem
When creating runtime unit tests for Alloy, I have a common expectation that I can identify an object as a Titanium proxy, and in certain cases can tell (roughly) what type of component that proxy is. The very basic code for this is as below:
// using a recent underscore.js
var _ = require('underscore')._
var someObject = Ti.UI.createWindow();
// (roughly) identify a Ti.UI.Window
if (_.isFunction(someObject.open)) {
// this and other criteria ID this object as a Ti.UI.Window
}
The above code successfully identifies the 2 conditions on iOS, Android, and Mobileweb. On Blackberry though the conditions always return false. This has the dual problem of introducing a parity issue between BB and the other platforms, and it also breaks many of Alloy's runtime unit tests, making it very difficult to reliably test Blackberry builds.
expected
Blackberry should behave as the other platforms and return true for the function-based Titanium proxy checks.
applyProperties is not implemented on BlackBerry right now, so it will be undefined. addEventListener might be a better choice for detecting proxies at this moment for all platforms. We could probably implement this method (or at least stub it out) on BlackBerry as well which can be our action item for this ticket.
Josh, this doesn't explain why it returns false though when I do isFunction() on a Window's open() function.
Looked into the typeof check of window.open() and it seems we are just returning a callable object rather than a normal function object instance. This is wrong and something we should address.
thanks for digging in so quickly josh, much appreciated
Test Case
Expected: This log statement should be printed: "typeof win.open = function"
Created pull request [#43](https://github.com/appcelerator/titanium_mobile_blackberry/pull/43) for master.
Verified fixed on: Mac OSX 10.9 Mavericks Titanium Studio, build: 3.2.0.201311122225 Titanium SDK, build: 3.2.0.v20131113094843 CLI: 3.2.0 Alloy: 1.3.0 BlackBerry Simulator: 10.2.0.1791 BlackBerry identifies functions via JavaScript using Test Case provided in comments. Closing.