根据我的理解,JavaScript没有整数或浮点数,而只是一个数字类型,它被格式化为双精度64位浮点值,但JavaScript也有类型数组,可以是多种类型,包括:Int32Array,Uint32Array,和Float32Array.
所以我的问题是:下面的类型化数组只使用带有一些位操作包装函数的Number类型,还是实际使用其他一些数据类型?如果它们确实使用了其他类型,那么是否可以通过包装类型化数组来实际创建自己的int和float类型.
在下面的代码中,我创建了一个名为Slates的对象,并为其添加了一些函数.
"use strict";
function Slates() {
this.canvas;
this.ctx;
this.width;
this.height;
}
Slates.prototype.init = function() {
this.canvas = document.getElementById("canvas");
this.ctx = this.canvas.getContext("2d");
this.resize();
};
Slates.prototype.resize = function() {
this.width = window.innerWidth;
this.height = window.innerHeight;
this.canvas.width = this.width;
this.canvas.height = this.height;
console.log("resizing");
};
Slates.prototype.render = function() {
this.ctx.clearRect(0, 0, this.width, this.height);
this.ctx.fillStyle = "rgba(0,0,100,.5)";
this.ctx.fillRect(0, 0, this.width, this.height);
};
window.onload = function() {
var slates = new Slates();
slates.init();
window.onresize = slates.resize;
window.requestAnimationFrame(slates.render);
};
Run Code Online (Sandbox Code Playgroud)
问题是,当我通过函数slates.render作为回调到一个函数,如window.requestAnimationFrame该this关键字指向window …