小编Mar*_*zzo的帖子

拥有高于 Number.MAX_SAFE_INTEGER 的值有什么意义?

JavaScriptNumber.MAX_SAFE_INTEGER. 任何超出此范围的数字都有不准确的风险。这是因为如本答案所述,由于位移动它无法在内存中准确表示:

var max = Number.MAX_SAFE_INTEGER;

max + 0;    // 9,007,199,254,740,991
max + 1;    // 9,007,199,254,740,992
max + 2;    // 9,007,199,254,740,992 (!)
max + 3;    // 9,007,199,254,740,994
max + 4;    // 9,007,199,254,740,996 (!)
// ...
Run Code Online (Sandbox Code Playgroud)

您在上面得到的任何结果max都非常不可靠,使其几乎完全无用,并且如果开发人员没有预料到或意识到此限制,则很容易导致错误。

我的问题是,超过这个值的数字有什么意义?JavaScript 是否有任何实际用途来允许Number超出此范围?它可以达到Number.MAX_VALUE(1.79e+308),大大大于MAX_SAFE_INTEGER,但是这两个值之间的所有内容都不是很有用,它迫使开发人员切换到BigInt

javascript

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

Vue.js - 为什么我的父组件在子组件安装之前安装?

我正在使用 Nuxt 版本2.15.7和 Vue 2.6.14。我的理解是,子组件是在父组件安装之前安装的,如本答案中所述

然而,在我的项目中,我遇到了相反的情况:

家长.vue

<template>
    <div class="parent">
        <MessageCard ref="messageCard"></MessageCard>
    </div>
</template>

<script>
export default {
    mounted() {
        console.log("Parent Mounted");
        console.log(this.$refs.messageCard); // undefined
    }
}
</script>
Run Code Online (Sandbox Code Playgroud)

消息卡.vue

<template>
    <div class="messageCard">Hello</div>
</template>

<script>
    export default {
        mounted() {
            console.log("Child mounted");
        }
    }
</script>
Run Code Online (Sandbox Code Playgroud)

我的控制台上的输出显示:

Parent mounted
undefined
Child mounted
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

根据vue 论坛 子组件不应该在父组件之前安装吗?我需要对孩子调用方法,但它是undefined. 我什至尝试过this.$nextTick(),却发现相同的结果。我了解我链接的资源分别来自 2018 年和 2017 年……这种行为在过去 4 年里有变化吗?

vue.js vue-component nuxt.js

5
推荐指数
0
解决办法
869
查看次数

Typescript 使用 .getElementsByClassName() 返回类型

getElementsByClassName当我调用两个不同的元素时,我很难理解结果的差异:

考虑以下代码:

let section:HTMLElement = document.getElementById("mainSection");

// This returns NodeListOf<Element>
let blah1 = section.getElementsByClassName("blah");

// This returns HTMLCollectionOf<Element>
let blah2 = document.getElementsByClassName("blah");
Run Code Online (Sandbox Code Playgroud)

为什么当我在 on 上调用该方法时,section我得到一个NodeList,但是当我在 document 上调用它时,我得到一个HTMLCollection

根据MDN 文档,它们不应该都返回一个 吗HTMLCollection

javascript dom selector typescript

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

无法解析模块说明符三

我正在尝试研究 Three.js,现在这次是在三个模块中。我使用express作为后端服务器。

我不断收到以下错误:

未捕获的类型错误:无法解析模块说明符“三”。相对引用必须以“/”、“./”或“../”开头。在我的控制台中。

这是app.js的后端代码

 "use strict";

 const express = require("express");
 const app = express();
 const path = require("path");

 const port = process.env.PORT || 9000;

 app.use(express.static(__dirname + "/public"));

 app.use("/build/", express.static(path.join(__dirname, "node_modules/three/build")));
 app.use("/jsm/", express.static(path.join(__dirname, "node_modules/three/examples/jsm")));

 app.get("/", (req, res) => {
 response.send("Connected successfully");
});

app.listen(port, (error) => {
 if (error) {
  console.warn(`${error} occured while starting server`);
  return;
 }
 console.log(`listening successfully to the port ${port}`);
});
Run Code Online (Sandbox Code Playgroud)

这是我的 js 文件:

import * as THREE from "/build/three.module.js";
import { OrbitControls } from "/jsm/controls/OrbitControls.js";
import …
Run Code Online (Sandbox Code Playgroud)

javascript webgl express three.js ecmascript-6

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

ThreeJS:从相机视图获取世界坐标

我想对平面顶点进行动画处理以填充屏幕。(顶点,因为这是我想要的效果,我希望为每个顶点设置短暂的延迟,然后填充屏幕)

作为概念证明,我使用下面的函数将顶点动画到随机点 -

tileClick() {
var geo = this.SELECTED.geometry;
var mat = this.SELECTED.material as THREE.MeshBasicMaterial;
TweenMax.TweenLite.to(geo.vertices[0], 0.3, {x: -5, y:5, onUpdate: () =>{
    mat.needsUpdate = true;
    geo.colorsNeedUpdate = true;
    geo.elementsNeedUpdate = true;

  }, ease: TweenMax.Elastic.easeOut.config(1, 0.5)});
}
Run Code Online (Sandbox Code Playgroud)

但是,现在我需要计算出相机当前视图的点。伪代码:camera.view.getBoundingClientRect();

WIP 的 Plnkr - https://next.plnkr.co/edit/Jm4D2zgLtiKBGghC

three.js

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

Javascript:我如何在不同的类之间进行通信?

我正在尝试使用Javascript中的类(感谢本指南).我已经学会了如何创建类的实例,以及如何嵌套它们,但我不知道如何让子类与其父类进行通信.

这是我的基本示例:我有一个具有数组的Board类allPieces,其中包含20 Piece个子对象.

function Board(){
    this.allPieces = [];
    this.selectedPiece = null;
    for(var i = 0; i < 20; i++){
        this.allPieces.push(new Piece(i));
    }
}

Board.prototype.makeSelection = function(currentPiece){
    this.selectedPiece = currentPiece;
}

function Piece(index){
    this.type = index;
    this.jqObject = $(".piece").eq(this.type);
    this.jqObject.click(function(){
        this.pieceClicked();
    }.bind(this));
}

Piece.prototype.pieceClicked = function(){
    Board.makeSelection(this); // <------ This gives me an error!
    // How do I tell Board that a selection has been made?
}

new Board();
Run Code Online (Sandbox Code Playgroud)

我可以通过电话从董事会沟通到一this.allPieces[0].anyMethod()件事但是,我不知道如果点击它就会从Piece传递到它的父母董事会; 我收到错误"Board.makeSelection不是函数".我如何告诉董事会已选择一件作品?

我已经尝试将一个var名称分配给Board var game …

javascript oop inheritance class

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