Roh*_*hit 4 javascript v8 embedded-v8 html5-canvas
大师我想了解Google-V8引擎的工作原理,据我所知,我浏览了https://developers.google.com/v8/get_started,V8将javascript作为输入,然后编译它并获得输出,如上面的示例所示,我们将其作为字符串输出。在现实生活中,情况有所不同,考虑这个画布代码
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);
};
})();
Run Code Online (Sandbox Code Playgroud)
这些代码在V8中是如何执行的,特别是canvas.addEventListener,可以一些线索并帮助我理解它。
v8 是可嵌入的 JavaScript 引擎。该引擎与 Canvas、getElement 或任何其他特定于浏览器的功能无关。v8 只会回调浏览器代码以在您的 javascript 代码中执行某些操作。您提到的链接是如何开始将 v8 嵌入到 C++ 应用程序中的文档。这样你就可以用JavaScript控制你自己的应用程序资源。您可以控制的资源都是您的,无论是文件、图形、窗口还是设备和小工具。
还有另一个项目将 v8 的强大功能与 HTML 渲染引擎相结合,这个项目称为 Chromium 浏览器。
| 归档时间: |
|
| 查看次数: |
953 次 |
| 最近记录: |