-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to work in non-browser env #85
base: master
Are you sure you want to change the base?
Conversation
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see your point @cpansprout . Do you mean to say that in browser you want convnetjs to be a global var (accessed without going through the window var)?
@@ -1,7 +1,7 @@ | |||
(function(lib) { | |||
"use strict"; | |||
if (typeof module === "undefined" || typeof module.exports === "undefined") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This already takes care of seeing if you are in browser env or not. Node env has module/module.exports, otherwise you are loading the lib from browser, thus window
will be defined.
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 |
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
line, which is actually unnecessary, as 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. |
‘window’ is specific to browser environments. The convnetjs variable has already been made into a global variable at this point, so the assignment is redundant. This allows it to work in non-browser environments other than node.
Thank you. That worked. |
‘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.