So, the short version, I do not understand, is a line of code:
(new Function("paper", "window", "document", cd.value)).call(paper, paper);
In the long version, consider the following functions:
window.onload = function () {
var paper = Raphael("canvas", 640, 480);
var btn = document.getElementById("run");
var cd = document.getElementById("code");
(btn.onclick = function () {
paper.clear();
paper.rect(0, 0, 640, 480, 10).attr({fill: "#fff", stroke: "none"});
try {
(new Function("paper", "window", "document", cd.value)).call(paper, paper);
} catch (e) {
alert(e.message || e);
}
})();
};
This code is from Raphael's playground, which means that it implements the raphael library. Thus, the only line of code at the top that I do not understand (it is inside the try / catch expression), suppose to copy the code that the user enters, which is stored inside the cd.value into the function. But how is this possible?
You can visit the page here: http://raphaeljs.com/playground.html
source
share