From 5245436e3676f88eb063da2d8509a4c382cd18a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 10 Oct 2018 23:10:51 +0200 Subject: [PATCH] Do not polute global scope with paper object Closes #1544 --- src/core/PaperScript.js | 8 +++++--- src/export.js | 2 +- src/init.js | 1 - 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/PaperScript.js b/src/core/PaperScript.js index 9d4eaf4115..94d7a2deff 100644 --- a/src/core/PaperScript.js +++ b/src/core/PaperScript.js @@ -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); diff --git a/src/export.js b/src/export.js index 34893d3af0..0ac7f578d7 100644 --- a/src/export.js +++ b/src/export.js @@ -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, diff --git a/src/init.js b/src/init.js index 55ae313b85..7083208b3a 100644 --- a/src/init.js +++ b/src/init.js @@ -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