小编GN.*_*GN.的帖子

Lodash辩解不起作用

const { debounce } = require('lodash');

debounce(
   () => {
     console.log('testing..');
   },
  1000,
  { leading: true, trailing: false }
);
Run Code Online (Sandbox Code Playgroud)

上面的代码不起作用.
https://lodash.com/docs/4.17.4#debounce 文档中的所有示例都使用命名函数.
使用Loash debounce与匿名函数有问题吗?

javascript lodash

5
推荐指数
2
解决办法
7762
查看次数

是否可以在字符串模板中插入 Javascript 正则表达式匹配?

例如...(这失败了)

\n\n

\r\n
\r\n
const currencyMap = {\r\n  "$": "USD",\r\n  "\xe2\x82\xac": "EUR",\r\n};\r\n\r\nconst r = \'$100\'.replace(/(\\$)([0-9]*)/g, `${currencyMap[$1]}$2`);\r\nconsole.log(r);
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n\n

有没有办法让这种事情起作用? \n$1在字符串中使用时可用,但不能用作键。

\n

javascript regex

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

Puppeteer:setDefaultNavigationTimeout 为 0 仍然超时

每次我运行这个脚本时都会超时。是否setDefaultNavigationTimeout真正避免超时?

我浏览了大约 26 个 URL,每个页面都有大量图像。无法想象 Puppeteer 仅仅因为图片太重而无法处理这些页面?

const url = 'test.com';
const jsonReturn = [];


async function runScraper() {

  const browser = await puppeteer.launch(prodConfig);

  const page = await browser.newPage({
    timeout: 0
  });

  page.setDefaultNavigationTimeout(0);
  await page.goto(url, { waitUntil: 'domcontentloaded' });
  await page.waitForSelector('.featured-shows-featured-show');

  let featuredShowsURLs = await page.$$eval('.featured-shows-featured-show > a', (links) => {
    return links.map(link => {
      return link.href;
    });
  });


  featuredShowsURLs = _.uniq(featuredShowsURLs)

  for (const featuredShowsURL of featuredShowsURLs) {
    const page = await browser.newPage({
      timeout: 0
    });
    try { …
Run Code Online (Sandbox Code Playgroud)

javascript puppeteer

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

捕获 Javascript 类方法中的所有异常

有没有办法捕获 Javascript 类方法中的所有异常?

class Foo {
  method1() {}
  method2() {}
  methodToCatchAllError() {}
}
Run Code Online (Sandbox Code Playgroud)

并处理该类的本地异常?

rescue_from在 Ruby 中以类似的方式工作

javascript

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

无法在 VSCode 中检测到 TypeScript 版本,并且 TS Intellisense 无法工作

TypeScript 已全局安装

以下是我执行时的终端输出tsc --version

tsc --version

// Output: Version 3.8.3
Run Code Online (Sandbox Code Playgroud)
  • 我没有在状态栏中看到 TypeScript“版本”。

  • 从命令面板中选择 TypeScript 版本只是空白。

没有获得 Typescript 的任何 Intellisense。

我怎样才能让它发挥作用?

typescript visual-studio-code

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

Typescript / React:带有函数语句的类型中缺少属性“children”

我有一个需要孩子的 React 组件。

收到 Typescript 错误:

Property 'children' is missing in type ... but required in type 'FixedWidthLayout'

该组件的定义类似于函数语句。

export default function FixedWidthLayout { ... }

我不想写像和表达..

IE

export const FixedWidthLayout = () => {...}

因此,做一些像...

const FixedWidthLayout: React.FC<Props> = () => {...}

..不是一个选择。

如何通过函数语句在 Typescript 中实现此功能?

typescript reactjs

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

为什么不可能使用 Truffle 部署智能合约(到主网)?

为什么使用 Truffle 部署到主网如此困难?

这是尝试部署到主网的概述......

  1. 当前 Gasprice 为 110 威。所以110000000000 wei

让我们插上它..

mainnet: {
      provider: () =>
        new HDWalletProvider({
          mnemonic: { phrase: process.env.MNEMONIC },
          providerOrUrl: process.env.RPC_URL_1_WSS,
        }),
      network_id: 1, 
      from: process.env.DEPLOYERS_ADDRESS,
      gasPrice: 110000000000, /*  GAS PRICE!! */
      confirmations: 2,
      timeoutBlocks: 200,
      skipDryRun: false, public nets )
    },
  },
Run Code Online (Sandbox Code Playgroud)
  1. 让我们来估算一下部署的 gas 成本。这将在 的gas参数中设置truffle-config

NODE_ENV=production truffle migrate --network mainnet --dry-run

Summary
=======
> Total deployments:   2
> Final cost:          0.001403824 ETH
Run Code Online (Sandbox Code Playgroud)

0.001403824 ETH 是 2.04 美元。
所以这很可能是错误的。

??失败?? …

ethereum smartcontracts truffle consensys-truffle

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

类型“Window &amp; typeof globalThis”上不存在属性。即使它是在定义文件中定义的

这是global.d.ts

interface Window {
  routes: any;
  routeMaker: any;
  store: any;
  searchKey: string;
}
Run Code Online (Sandbox Code Playgroud)

据我了解,任何事物global.d.ts本质上都是一样的

declare global {
  interface Window {
    routes: any;
    routeMaker: any;
    store: any;
    searchKey: string;
  }
}

Run Code Online (Sandbox Code Playgroud)

坐在根目录中,是tsconfig.json我指向的定义文件。

{
  "compilerOptions": {
    "target": "es6",
    "declaration": false,
    "emitDecoratorMetadata": true,
    "baseUrl": ".",
    "experimentalDecorators": true,
    "lib": ["es6", "dom", "webworker"],
    "module": "es6",
    "moduleResolution": "node",
    "sourceMap": true,
    "jsx": "react",
    "typeRoots": ["node_modules/@types", "types"],
    "types": ["node", "webpack-env"],
    "downlevelIteration": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true
  },
  "exclude": ["**/*.spec.js", "node_modules", "vendor", "public"],
  "include": …
Run Code Online (Sandbox Code Playgroud)

typescript

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

“async/await”链中的所有函数都必须使用“async/await”关键字吗?

链中的所有函数都async/await必须使用async/await关键字吗?

async function one() {
  return await fetch(.....);
}

async function two() {
  return await one();
}

async function three() {
  return await two();
}
Run Code Online (Sandbox Code Playgroud)

我在教程中看到了一些示例,其中调用者不必使用关键字。

javascript async-await

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

更漂亮的 VSCode。设置单引号,但始终将其更改为双引号

  1. 在 VSCode 中使用Prettier扩展。

  2. 设置Single Quote为单人。

  3. format onSave设置为 true。

还是... 当我点击保存时,单引号会转换为双引号..

为什么?为什么?为什么?为什么?


此外...

  1. 我已将 eslint 设置为使用单引号
  2. 我什至从 VSCode 中删除了 eslint 扩展。
// in .eslint file
"quotes": [2, "single", { "avoidEscape": true }],
Run Code Online (Sandbox Code Playgroud)

还是... 当我点击保存时,单引号会转换为双引号..

为什么?

visual-studio-code prettier

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