小编Ara*_*oca的帖子

数组中的"......"(三点)符号是什么意思?

我不明白这个...符号到底是做什么的.

我尝试了一个简单的例子,用Babel来理解它(查看示例),但似乎:

ES6语法

let myArray = [1, 2, 3, ...18];

console.log(myArray); // [1, 2, 3]
console.log(myArray[4]);// undefined
console.log(myArray.length); // 3
Run Code Online (Sandbox Code Playgroud)

此ES5语法相同:

"use strict";

function _toConsumableArray(arr) { 
    if (Array.isArray(arr)) { 
        for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
             arr2[i] = arr[i];
        }
        return arr2;
     } else { 
        return Array.from(arr); 
     } 
}

var myArray = [1, 2, 3].concat(_toConsumableArray(18));

console.log(myArray); // [1, 2, 3]
console.log(myArray[4]); // undefined
console.log(myArray.length); // 3
Run Code Online (Sandbox Code Playgroud)

但是:这段代码有什么作用?因为output( …

javascript arrays ecmascript-6

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

Angular2:Web Speech API - 语音识别

在阅读了webkitSpeechRecognition(Javascript中的语音识别)的文档后,我尝试在Angular 2中实现它.

但是当我这样做时:

const recognition = new webkitSpeechRecognition();
Run Code Online (Sandbox Code Playgroud)

TypeScript说这个错误:

[ts] Cannot find name 'webkitSpeechRecognition'. any
Run Code Online (Sandbox Code Playgroud)

如果我尝试从窗口中提取webkitSpeechRecognition:

if ('webkitSpeechRecognition' in window) {

    console.log("Enters inside the condition"); // => It's printing

    const { webkitSpeechRecognition } = window; // => TypeScript Error
    const recognition = new webkitSpeechRecognition();
}
Run Code Online (Sandbox Code Playgroud)

如果我评论console.log打印的最后两行,请进入条件!webkitSpeechRecognition存在于窗口内!但是如果没有注释最后两行,那么TypeScript错误就是这样:

[ts] Type 'Window' has no property 'webkitSpeechRecognition' and no string index signature.
const webkitSpeechRecognition: any
Run Code Online (Sandbox Code Playgroud)

如何在Angular 2中创建新的识别?有人试过吗?

javascript voice-recognition webspeech-api typescript1.8 angular

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

Angular 1.5 Component:传递一个函数

是否可以将函数传递给组件并在传递参数的组件内调用此函数?

例:

帖子列表

<post-list posts="blog.posts"
           loading="blog.loadingPosts"
           get-post-url="blog.getPostUrl" 
           is-user-authenticate="blog.user">
</post-list>
Run Code Online (Sandbox Code Playgroud)

getPostUrl是一个函数(在容器控制器内):

const getPostUrl = (postId) => {
    const protocol = $location.protocol();
    const host = $location.host();
    const port = $location.port();

    return protocol + "://" + host + "" + (port !== 80 ? ":" + port : "") + "/blog/post/" + postId;
};
Run Code Online (Sandbox Code Playgroud)

帖子列表:组件

const PostList = {
  "bindings": {
    "posts": "<",
    "loading": "<",
    "getPostUrl": "&", //Function getPostUrl
    "isUserAuthenticate": "<"
  },
  "template": `<div>
                <div class="col-md-9 text-center" data-ng-if="$ctrl.loading">
                  <i class="fa …
Run Code Online (Sandbox Code Playgroud)

javascript components angularjs

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

如何在CSS中的三角形上应用投影?

我在CSS中有这个三角形:

.triangle {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 200px 200px 0 0;
  border-color: #007bff transparent transparent transparent;
}
Run Code Online (Sandbox Code Playgroud)
<div class="triangle"></div>
Run Code Online (Sandbox Code Playgroud)

如何在斜边线上应用1px阴影?

html css css3

11
推荐指数
3
解决办法
8147
查看次数

错误:在angular-cli中找不到模块'lodash'?

OS

Mac OSX El Capitan

版本

angular-cli: 1.0.0-beta.8, node: 6.2.0,os: darwin x64

描述

我试图lodash在angular-cli项目中添加库:

  • npm install --save lodash
  • typings install lodash --global --save

已成功安装node_modules.

system-config.ts:

/** Map relative paths to URLs. */
const map: any = {
  'lodash': 'vendor/lodash',
};

/** User packages configuration. */
const packages: any = {
  'lodash': {
    format: 'cjs',
    defaultExtension: 'js',
    main: 'core.js'
  }
};
Run Code Online (Sandbox Code Playgroud)

角-CLI-build.js

var Angular2App = require('angular-cli/lib/broccoli/angular2-app');

module.exports = function(defaults) {
  return new Angular2App(defaults, …
Run Code Online (Sandbox Code Playgroud)

angular-cli angular

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

React 16.14.0:未捕获错误 ReferenceError:未定义导出

我是next-translate库的作者,我正在开发一个实验版本,我在 React 16.14.0 中遇到错误,我不明白为什么会发生这种情况。将 React 升级到版本 17 然后它工作正常,但我不想强迫每个使用我的库的新版本的人迁移他们的 React 版本。

我创建了一个可重现的错误示例:https : //github.com/aralroca/next-translate-error-reproduction

为了重现这个问题:

  • 克隆这个 repo
  • yarn && yarn dev
  • 打开 localhost:3000
  • 打开开发者工具

Error was not caught ReferenceError: exports is not defined

我的库的预发布代码在这里:

配置文件

{
  "compilerOptions": {
    "strict": false,
    "module": "es6",
    "target": "es5",
    "jsx": "react",
    "removeComments": true,
    "moduleResolution": "node",
    "esModuleInterop": true,
    "declaration": true,
    "lib": ["esnext", "dom"],
    "allowJs": true,
    "forceConsistentCasingInFileNames": true,
    "outDir": "./lib/esm"
  },
  "include": ["./src"]
}
Run Code Online (Sandbox Code Playgroud)

tsconfig-cjs.json

{
  "extends": …
Run Code Online (Sandbox Code Playgroud)

javascript typescript reactjs webpack next.js

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

RxJS比命令更快吗?

我是功能编程和功能反应式编程的新手.

我多次阅读功能反应式编程的强大功能.

好; 可读,避免副作用等

但是......我不知道如何以功能/反应的方式改进我的代码,以比命令式方式更快地执行.可能吗?也许我想念一些东西?因为在我的函数式编程中,代码是针对每个任务进行迭代的:对于filter,map,reduce ...而且这个更慢.可以做一次迭代的所有事情吗?也许用compose()

谢谢.

性能测试:势在必行与FP对比FRP

var array = [];
var i, l;

//INIT ARRAY
for (i = 0; i < 15000; i += 1) {
  array[i] = i;
}

// WITH IMPERATIVE
console.time("IMPERATIVE");
var sum = 0;
var a;
var result = [];
for (i = 0, l = array.length; i < l; i += 1) {
  a = array[i];
  if (a % 2 === 0) {
    result.push(a * …
Run Code Online (Sandbox Code Playgroud)

javascript functional-programming reactive-programming rxjs

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

MEANJS:将base64映像发送到服务器的最佳方式

情况

我正在使用MEAN.JS框架(MongoDB,ExpressJS,AngularJSNodeJS).

在frontEnd中使用AngularJS ; 我在一个字段中有一个带有base64编码图像JSON.

我想要的是?

  • 我想将此JSON发送到服务器(NodeJS).

我正在使用RESTful:

控制器:

var article = new Articles ($scope.article);


article.$save(function(response) {
    //If all is OK
}, function(errorResponse) {
    //Error 
 });
Run Code Online (Sandbox Code Playgroud)

$scope.article有一个名为" image " ($ scope.article.image)的字段,其中包含图像的base64字符串.

服务:

(function() {
'use strict';

angular
    .module('articles')
    .factory('articles', ['$resource',

    function($resource) {
        return $resource('articles/:articleId', { articleId: '@_id'
        }, {
            update: {
                method: 'PUT'
            }
        });
    } …
Run Code Online (Sandbox Code Playgroud)

base64 mongodb node.js angularjs meanjs

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

Javascript:Unshift到数组的第二个位置

我理解这个图:

Unshift/Push图表

但现在我的问题是...... 如何在数组的第二个位置添加一个元素?

如果我有这个数组:(A,C,G,T)我想添加B ...

我想要的结果应该是:(A,B,C,G,T)

有什么建议?

谢谢!

javascript arrays

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

如何使用 Next.js 检查自定义服务器中是否存在页面

使用next@9.1.7与快递的自定义服务器。如何server.jshandle(req, res)调用之前知道next.js 页面是否存在?

我试过,app.router.execute但它总是返回 false。所以我想那不是办法。我检查了 Next.js 文档,但没有得到任何解决方案......有人有想法吗?

const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const server = express()
const handle = app.getRequestHandler()

// ...

server.get('*', async (req, res) => {
  const { url, fixed } = fixUrl(req)

  // pageExists is always false ...
  const pageExists = await app.router.execute(req, res, req.url) 

  // Fix the url and redirect only if the page exists 
  // (to avoid redirects to 404 …
Run Code Online (Sandbox Code Playgroud)

javascript node.js express reactjs next.js

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