convnetjs
convnetjs copied to clipboard
Allow to work in non-browser env
‘window’ is specific to browser environments. ‘this’ (the global object is the default ‘this’ value) allows it to work in non-browser environments other than node.
Oh, wait. That doesn’t work, nor does it make any sense.
The "use strict" prevents ‘this’ from returning the global object. But in any case, you don’t even need this, since you are already defining a convnetjs variable. (The combined file begins with ‘var convnetjs’.)
So I suspect that line can simply be deleted, but I am not certain.
I am not using a browser. Nor am I using Node. I am embedding a JavaScript interpreter directly in my application. The JS environment contains only objects defined by the ECMAScript specification. This means I get an error when trying to run convnet.js, since it is trying to access nonexistent variables.
(I happen to be using Duktape, but I could have used SpiderMokney or JE and the same problem would have occurred.)
In a browser environment, BTW, the window is the global object, which happens to have a window
property referring to itself (so, yes, you can say window.window.window.window.convnetjs
).
Thanks @cpansprout , I understand now. I don't know how to help you out there / how to debug as I've never run JS in such an environment. If you get around solving it, it'd be cool to make to look into the solution
I have solved it locally by simply commenting out the
window.convnetjs = lib;
line, which is actually unnecessary, as convnetjs
has already been declared as a global variable. If you change that line to alert(window.convnetjs == lib)
then you will get an alert box saying ‘true’.
I don’t know how you update an existing pull request.
@cpansprout you can do that by pulling your fork of the repo and checking out the patch-1 branch (this). Then you modify that, commit, push, and you should see the new commit appear here.
Thank you. That worked.