Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cpansprout
Copy link

‘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.

@cpansprout
Copy link
Author

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.

Copy link

@sacdallago sacdallago left a 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") {

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.

@cpansprout
Copy link
Author

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).

@sacdallago
Copy link

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

@cpansprout
Copy link
Author

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.

@sacdallago
Copy link

@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.
@cpansprout
Copy link
Author

Thank you. That worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants