小编Viv*_*vek的帖子

JavaScript数据类型

根据我的理解,JavaScript没有整数浮点数,而只是一个数字类型,它被格式化为双精度64位浮点值,但JavaScript也有类型数组,可以是多种类型,包括:Int32Array,Uint32Array,和Float32Array.

所以我的问题是:下面的类型化数组只使用带有一些位操作包装函数的Number类型,还是实际使用其他一些数据类型?如果它们确实使用了其他类型,那么是否可以通过包装类型化数组来实际创建自己的intfloat类型.

javascript arrays types number-formatting

5
推荐指数
1
解决办法
580
查看次数

使此关键字引用实例而不是窗口对象

在下面的代码中,我创建了一个名为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.requestAnimationFramethis关键字指向window …

javascript oop prototype

1
推荐指数
1
解决办法
338
查看次数

标签 统计

javascript ×2

arrays ×1

number-formatting ×1

oop ×1

prototype ×1

types ×1