如何在Google V8相关代码中执行JavaScript
大师我想了解Google-V8引擎的工作原理, 据我所知,V8采用javascript作为输入,然后编译它并获得输出,就像上面的示例中我们以字符串形式输出一样。 在现实生活场景中,不同的是考虑这个画布代码如何在Google V8相关代码中执行JavaScript,javascript,html5-canvas,v8,embedded-v8,Javascript,Html5 Canvas,V8,Embedded V8,大师我想了解Google-V8引擎的工作原理, 据我所知,V8采用javascript作为输入,然后编译它并获得输出,就像上面的示例中我们以字符串形式输出一样。 在现实生活场景中,不同的是考虑这个画布代码 var canvas = document.getElementById("canvas"), ctx = canvas.getContext("2d"), // Create canvas context W = window.innerWidth, // W
var canvas = document.getElementById("canvas"),
ctx = canvas.getContext("2d"), // Create canvas context
W = window.innerWidth, // Window's width
H = window.innerHeight, // Window's height
particles = [], // Array containing particles
ball = {}, // Ball object
paddles = [2], // Array containing two paddles
mouse = {}, // Mouse object to store it's current position
points = 0, // Varialbe to store points
fps = 60, // Max FPS (frames per second)
particlesCount = 20, // Number of sparks when ball strikes the paddle
flag = 0, // Flag variable which is changed on collision
particlePos = {}, // Object to contain the position of collision
multipler = 1, // Varialbe to control the direction of sparks
startBtn = {}, // Start button object
restartBtn = {}, // Restart button object
over = 0, // flag varialbe, cahnged when the game is over
init, // variable to initialize animation
paddleHit;
// Add mousemove and mousedown events to the canvas
canvas.addEventListener("mousemove", trackPosition, true);
canvas.addEventListener("mousedown", btnClick, true);
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function( callback ){
return window.setTimeout(callback, 1000 / 60);
};
})();
这些代码是如何在V8中执行的,特别是canvas.addEventListener,可以帮助我理解它。V8是可嵌入的JavaScript引擎。此引擎与Canvas、getElement或任何其他特定于浏览器的功能无关。v8只是回调浏览器代码,从javascript代码中执行一些操作。您提到的链接是一个文档,如何开始将V8嵌入到C++应用程序中。因此,您可以使用JavaScript控制自己的应用程序资源。您可以控制的资源是您自己的,可以是文件、图形、窗口、设备和小工具
还有一个项目将v8的强大功能与HTML渲染引擎结合在一起,这个项目称为Chromium browser。v8与调用
canvas.addEventListener
时发生的事情关系不大。另一方面,Chrome的DOM和事件层与此相关。其他的如document.getElementById(“canvas”)或window.requestAnimationFrame,你能告诉我一些文档吗?人们甚至没有告诉你方向,但投你反对票——我很惊讶这个问题被否决了,但这只是一个否决票,只有一个人。