小编sou*_*ubi的帖子

为什么我无法访问打字稿类的构造函数中的抽象属性

abstract class Route {
    abstract readonly name?: string;
    protected abstract pattern: string;

    public constructor() {
        // Do something with `this.name` and `this.pattern`.
        
        console.log(this.pattern); // Typecheck error
    }
    
    abstract handle(): void;
}
Run Code Online (Sandbox Code Playgroud)

这会引发错误,因为this.pattern不会在构造函数中访问。为什么我无法访问它?

class abstract typescript

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

解构嵌套对象:如何获取父级及其子级值?

在下面的函数中,我得到了带有属性的textarea对象current.

这里,嵌套的解构与StartEnd变量一起工作.但current变量不起作用.

function someFunction({ current: { selectionStart: Start, selectionEnd: End } }, AppStateSetter) {

    // do something with current, Start, and End
}
Run Code Online (Sandbox Code Playgroud)

javascript destructuring reactjs react-ref

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

汇总错误:导入 Material-UI 组件时无法从 @babel/runtime 加载模块

我正在尝试index.js使用汇总编译此文件:

import React from "react";
import ReactDOM from "react-dom";
import Grid from "@material-ui/core/Grid";

ReactDOM.render(
    <React.StrictMode>
        <Grid container>
        </Grid>
    </React.StrictMode>,
    document.getElementById('root')
);

Run Code Online (Sandbox Code Playgroud)

rollup.config.js

import { nodeResolve } from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';

export default {
    input: 'index.js',
    output: {
        file: 'dist/bundle.js',
        format: 'iife'
    },
    plugins: [
        nodeResolve(),
        babel({ babelHelpers: 'bundled', exclude: /node_modules/ }),
        commonjs(),
    ],
};
Run Code Online (Sandbox Code Playgroud)

babel.config.json

{
    "presets": [
        "@babel/preset-react",
        "@babel/preset-env"
    ]
}
Run Code Online (Sandbox Code Playgroud)

现在,当我运行时,出现npx rollup -c此错误:

[!] 错误:无法加载 /home/recursive-beast/Desktop/repositories/myproject/node_modules/@babel/runtime/helpers/esm/objectWithoutProperties(由 …

javascript reactjs material-ui rollupjs

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

node.js 和 python 中相同问题解决方案的不同结果

我用一些代码解决了以下 leetCode 问题:


你有d骰子,每个骰子都有f编号为 1、2、...、f 的面。

返回模 10^9 + 7 的可能方式数来掷骰子,使面朝上的数字总和等于t.


我制作了两个版本的解决方案代码,一个在 node.js 中使用mathjs,另一个在 python 中使用 math 模块。

在 node.js 中

const { combinations: comb, bignumber: Big } = require("mathjs");

function dice(d, f, t) {
    if (t > d * f || t < d) return 0;

    var result = Big(0);
    var i = 0;
    var sign = 1;
    var n = t - 1;
    var k = t - d;

    while …
Run Code Online (Sandbox Code Playgroud)

javascript python bignum combinatorics arbitrary-precision

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