Skip to content

Commit

Permalink
Do not polute global scope with paper object
Browse files Browse the repository at this point in the history
Closes #1544
  • Loading branch information
lehni committed Oct 10, 2018
1 parent 4c035ad commit 5245436
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/core/PaperScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,13 @@ Base.exports.PaperScript = function() {
if (agent.firefox)
code = '\n' + code;
script.appendChild(document.createTextNode(
'paper._execute = function(' + params + ') {' + code + '\n}'
'document.__paperscript__ = function(' + params + ') {' +
code +
'\n}'
));
head.appendChild(script);
func = paper._execute;
delete paper._execute;
func = document.__paperscript__;
delete document.__paperscript__;
head.removeChild(script);
} else {
func = Function(params, code);
Expand Down
2 changes: 1 addition & 1 deletion src/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// NOTE: Do not create local variable `var paper` since it would shield the
// global one in the whole scope.

paper = new (PaperScope.inject(Base.exports, {
var paper = new (PaperScope.inject(Base.exports, {
Base: Base,
Numerical: Numerical,
Key: Key,
Expand Down
1 change: 0 additions & 1 deletion src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
// Node.js,only the files included in such a way see each other's variables in
// their shared scope.

/* global document:true, window:true */
// Set up a local `window` variable valid across the full the paper.js scope,
// pointing to the native window in browsers and the one provided by JSDom in
// Node.js
Expand Down

0 comments on commit 5245436

Please sign in to comment.