I have few pieces of scripts written already. However, the variables inside different script will surely collide with each other upon import
Some of the examples from my scripts
The following is script A
<script>
var vx = 0;
var vy = 0;
var d = null;
function init() { ...}
function CommentBox() { ... }
CommentBox.prototype.create = function() { ... }
</script>
The following is script B
<script>
var vx = 0;
var vy = 0;
var x = 0;
var y = 0;
var p = null;
function init() { ...}
function Ball() { ... }
Ball.prototype.create = function() { ... }
</script>
Upon import, variables and methods will surely collide with each other.
Here's my question. Is it possible to separate them without the need to modify the name? I know there exists some design patterns but how can I achieve this?
I have been using prototype pattern for various "object" in these script but I don't know how to do it when I have to apply it to whole script. Also is it possible to have nested Prototype?