Jump to content
Search Community

[node.js] using GSAP WITHOUT polluting the global scope.

Ciberman test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hello. I am trying to use GSAP with node.js WITHOUT polluting the global scope. 
I am ussing nw.js (so, I have available the window object)


First I do:

npm install gsap --save

Then in my Tween.js:

var gs = window.GreenSockGlobals = {};

console.log(gs); // logs empty object
console.log(window.GreenSockGlobals); // logs empty object
console.log(window); // logs the window object, with ALL the GSAP stuff in it
console.log(window.TweenLite); // logs tweenlite object

I don't want to have all the GSAP stuff in the global scope. I want to have it in a specified object. 

Link to comment
Share on other sites

Glad you got it working. 

I'm not an expert with node, but I wonder if it would have helped if you referred to "this" instead of "window", like:

var gs = window.GreenSockGlobals = {};
var gs = this.GreenSockGlobals = {};
var gs = global.GreenSockGlobals = {};

(that must be run before the GSAP files are loaded). 


Anyway, thanks for reporting back with what you changed. I'm also kinda curious about why it's important to you to avoid having GSAP values added to the global scope. Are you under the impression that there's a big performance issue (there's not)? 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...