我不明白这个...
符号到底是做什么的.
我尝试了一个简单的例子,用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( …
在阅读了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
是否可以将函数传递给组件并在传递参数的组件内调用此函数?
例:
帖子列表
<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) 我在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阴影?
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) 我是next-translate库的作者,我正在开发一个实验版本,我在 React 16.14.0 中遇到错误,我不明白为什么会发生这种情况。将 React 升级到版本 17 然后它工作正常,但我不想强迫每个使用我的库的新版本的人迁移他们的 React 版本。
我创建了一个可重现的错误示例:https : //github.com/aralroca/next-translate-error-reproduction
为了重现这个问题:
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) 我是功能编程和功能反应式编程的新手.
我多次阅读功能反应式编程的强大功能.
好; 可读,避免副作用等
但是......我不知道如何以功能/反应的方式改进我的代码,以比命令式方式更快地执行.可能吗?也许我想念一些东西?因为在我的函数式编程中,代码是针对每个任务进行迭代的:对于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)我正在使用MEAN.JS框架(MongoDB,ExpressJS,AngularJS和NodeJS).
在frontEnd中使用AngularJS ; 我在一个字段中有一个带有base64编码图像的JSON.
我正在使用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) 我理解这个图:
但现在我的问题是...... 如何在数组的第二个位置添加一个元素?
如果我有这个数组:(A,C,G,T)我想添加B ...
我想要的结果应该是:(A,B,C,G,T)
有什么建议?
谢谢!
使用next@9.1.7
与快递的自定义服务器。如何server.js
在handle(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 ×7
angular ×2
angularjs ×2
arrays ×2
next.js ×2
node.js ×2
reactjs ×2
angular-cli ×1
base64 ×1
components ×1
css ×1
css3 ×1
ecmascript-6 ×1
express ×1
html ×1
meanjs ×1
mongodb ×1
rxjs ×1
typescript ×1
webpack ×1