09-14-2012 12:27 PM
a new Thread as Follow-Up from
Peter,
perhaps you can reply your last answer to this Thread ?
09-14-2012 12:47 PM
Ekke, the "global object" refers to a sometimes-invisible object which is always in scope, and which provides all the names which are available without having to import or do anything. For example, you can always call parseInt(), or you can always "throw new Error('foo')" because parseInt and Error are both in the global object.
In a browser this is normally called "window", but in an environment like this there may be no direct way to get to the global object to inspect it. You can, however use this handy routine (as I found out): http://www.nczonline.net/blog/2008/04/20/get-the-j
With that function, you could assign the return value to, say "g", and do console.log(Object.getOwnPropertyNames(g)) or something like that (notice that both "console" and "Object" are available there because they too are in the global object), and you'd see this list:
Unfortunately it's incomplete, and I don't know why yet. At the very least, "Application" exists there, providing the ability to do "Application.quit()" from within the Javascript, but I haven't yet found either documentation nor a technique that would let one discover that as with the above.
As for substring() and such, Javascript has several -- substr(), substring(), and slice() -- depending on your goals. These sorts of things should all be standard and in any Javascript/ECMAscript documentation that covers the correct version. (Which version? I'm not 100% clear on that yet...)
Note: I posted what's probably in effect a duplicate of this thread as http://supportforums.blackberry.com/t5/Cascades-De
09-14-2012 12:52 PM
this is really cool Peter, that you found where JavaScript StandardLib functions were hidden.
ekke
09-14-2012 12:58 PM
09-14-2012 01:09 PM
peter9477 wrote:
Well, they're global, so not exactly hidden... any Javascript programmer wouldn't even think twice about using those, and would be quite puzzled to find if they *weren't* available globally.
I haven't found them before
tried something like
myTextField.text.substring()
and it failed
remember: I was a pure native Java developer before - no web, no javascript, ...
so: How would I do it to get a substring from a string property using the 'global object' ?
09-14-2012 01:24 PM
Yeah, I know your background. That's why I mentioned that. :-)
It looks like, at least on a Label and TextArea (which I just tested), you can do text.substring(m, n) on it to chop out a piece. Did you see an error in your log output, or what?
09-14-2012 01:44 PM
peter9477 wrote:
Yeah, I know your background. That's why I mentioned that. :-)
It looks like, at least on a Label and TextArea (which I just tested), you can do text.substring(m, n) on it to chop out a piece. Did you see an error in your log output, or what?
hmmmmm
I know it failed with something like unknown object or so - didn't remember exactly
was inside a function
just tried something like
if (name.length > 29) {
console.debug("JAVASCRIPT ******** "
+name.substring(29,name.length))
}
and it worked
magic .... anyway - thanks - now I have an idea what's supported
09-14-2012 03:43 PM
I've been exploring the names available in QML on the undocumented Application object.
The basic "Application.quit()" works fine, and finding a simple way to do that (really just in a few test apps to make it quicker to exit/restart than swiping up all the time) was what got me going on this.
Some of the other names are signals, and those could actually be useful as well:
import bb.cascades 1.0
Page {
onCreationCompleted: {
Application.swipeDown.connect(function() {console.log('swipeDown')});
Application.invisible.connect(function() {console.log('invisible')});
Application.aboutToQuit.connect(function() {console.log('aboutToQuit')});
Application.awake.connect(function() {console.log('awake')});
Application.fullscreen.connect(function() {console.log('fullscreen')});
Application.thumbnail.connect(function() {console.log('thumbnail')});
}
}
I played a bit and get the feeling some of these are flaky, which may well be why this isn't documented for QML yet.
For someone planning to do as much in QML as possible, the aboutToQuit() signal may be useful. That's called when the app is exiting (whether Application.quit() was called, or the user closed the app from Navigator) and although you can't prevent the termination, you could at least react to it... though I'm not yet sure what you could usefully do solely in QML... and if you're going to just call C++ you could connect to that signal in C++ in the first place.
Maybe the others are more reasonable to work with. I actually think I had swipeDown() responding at one point, and thought that might allow a pure-QML substitute for the missing Menu class (not yet supported in QML) but at the moment I get nothing for that one... thus my "flaky" comment.