Problems importing another JavaScript library into QML
-
wrote on 28 Dec 2012, 08:53 last edited by
I am working in Cascades/QML and am using JavaScript for handling my application logic. I have this external javascript library (a .js file) located inside the assets, so I do something like this
@import "libname.js" as Library@
and the library was designed such that it defined a global object like :
@LibGlobalObject = function (param) {
//Some action
};@and then it keeps adding methods by doing something like
@GoodLib.prototype.methodOne = function(param) { };
GoodLib.prototype.methodTwo = function(param) { };@and it says it can be used by doing something like :
@(new GoodLib(someParam)).methodOne(new GoodLib(someParam));
(new GoodLib(someParam)).methodTwo(new GoodLib(someParam));@so I thought of doing something like
@(new Library.GoodLib(someParam)).methodOne(new Library.GoodLib(someParam));
(new Library.GoodLib(someParam)).methodOne(new Library.GoodLib(someParam));@in my QML but it doesn't work.
Can anyone tell me what it is that I'm doing wrong here ?
-
wrote on 28 Dec 2012, 11:49 last edited by
What is GoodLib?
-
wrote on 28 Dec 2012, 11:55 last edited by
Sorry I seem to have made a mistake in posting here. It should be
@GoodLib = function (param) {
//Some action
};@and GoodLib is the name of the global object that the library creates so that I can do calls like :
@new GoodLib(someParam)@
-
wrote on 28 Dec 2012, 12:18 last edited by
OK. Your code looks good. What does not work for you? Do you get any error message?
The only thing that you must be aware about: each import creates independent space (or at least that's my impression). It is better to use properties for keeping global state.
4/4