Do not polute global scope with paper object

Closes #1544
This commit is contained in:
Jürg Lehni 2018-10-10 23:10:51 +02:00
parent 4c035ada36
commit 5245436e36
3 changed files with 6 additions and 5 deletions

View file

@ -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);

View file

@ -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,

View file

@ -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