关于
p = 0;
(p+1)++;
> ReferenceError: Invalid left-hand side expression in postfix operation
Run Code Online (Sandbox Code Playgroud)
和
p = 0;
++(p+4);
> ReferenceError: Invalid left-hand side expression in prefix operation
Run Code Online (Sandbox Code Playgroud)
我只是有点意外,因为我期望postfix/prefix运算符可以处理表达式的分辨率(括号具有最高的运算符优先级).
有人可以给我一两行来解释这里发生的事情吗?
谢谢
编辑:感谢您的快速回复,第一个答案标记为答案.我觉得我也应该从下面的@thefourtheye那里得到深刻的回答
每次我都无法处理所有事情.我试过了:
它适用于gulp-ngmin,但不适用于gulp-less
因此,只有在我更改test.js时才会处理test.js:
var SRC = 'test.js';
var DEST = 'dist';
gulp.task('test', function () {
return gulp.src(SRC)
.pipe(changed(DEST))
// ngmin will only get the files that
// changed since the last time it was run
.pipe(ngmin())
.pipe(gulp.dest(DEST));
});
Run Code Online (Sandbox Code Playgroud)
但每次我执行此任务时,它都会计算得越少
这有什么不对?
var SRC = 'test.less';
var DEST = 'dist';
gulp.task('test', function () {
return gulp.src(SRC)
.pipe(changed(DEST))
.pipe(less({
paths: [path.join(__dirname, 'less', 'includes')]
}))
.pipe(gulp.dest(DEST));
});
Run Code Online (Sandbox Code Playgroud) 我想clear在每次测试迭代之间自动执行mocha --watch.有没有一种很好的方法在(重新)运行mocha之前自动执行命令?
我有3个国家/地区的数组,并输入了一个文本来过滤它们。如果输入文本输入,它将检查针对国家名称输入的内容,这将返回与过滤后的文本匹配的新的过滤后的国家列表。它还应在旁边显示输入的文本Typed Text:
import React, { Component } from 'react'
import { View, Text, TextInput } from 'react-native'
import { observable, action } from 'mobx';
import { observer } from 'mobx-react/native'
@observer
export default class Country extends Component {
@observable filterTermValue;
@observable countriesList = [
{'slug': 'amsterdam', 'name': 'Amsterdam'},
{'slug': 'usa', 'name': 'United States'},
{'slug': 'vienna', 'name': 'Vienna'}
];
render() {
return (
<View>
<Text>Typed Text: {this.filterTermValue}</Text>
<TextInput placeholder="Start typing country"
value={this.filterTermValue}
onChange={this.onChangeFilterTerm} />
{this.countriesList.map(country =>
<View key={country.slug}>
<Text>{country.name}</Text>
</View> …Run Code Online (Sandbox Code Playgroud) 这适用于摩卡/柴:
describe('Chai throw() with old-style custom errors', ()=> {
// old way
function ES5Error(message = 'todo', value) {
this.name = 'ES5Error';
this.message = message;
}
ES5Error.prototype = new Error();
it('catches ES5Errors', ()=> {
var err = new ES5Error('This is a bad function.');
var fn = function () { throw err; }
expect(fn).to.throw(ES5Error);
expect(fn).to.throw(Error);
expect(fn).to.throw(/bad function/);
expect(fn).to.not.throw('good function');
expect(fn).to.throw(ES5Error, /bad function/);
expect(fn).to.throw(err);
});
});
Run Code Online (Sandbox Code Playgroud)
虽然基于类的方法不:
describe('Chai throw() with new-style custom errors', ()=> {
// New way
class ExtendError extends Error { …Run Code Online (Sandbox Code Playgroud) 鉴于这种:
var metadata = {
title: 'Scratchpad',
translations: [
{
title: 'JavaScript-Umgebung'
}
]
};
const output = ({
title: englishTitle,
translations: [{
title: localeTitle
}]
}) => (
console.log(englishTitle), // "Scratchpad"
console.log(localeTitle) // "JavaScript-Umgebung"
)
output(metadata);
Run Code Online (Sandbox Code Playgroud)
现在translations是未定义的:
console.log(JSON.stringify(translations)) // ? "undefined"
Run Code Online (Sandbox Code Playgroud)
问题:有没有办法translations在参数解构表达式中创建变量(例如,在函数参数括号内)
几个月后我才回到节点,我对我正在做的事情有点模糊
我更新了npm,node和gulp.我的gulp文件似乎工作,但我只是去安装gulp-compile-handlebars但我得到以下内容:
Cooldude-MacBook-Air:_overlay cooldude$ sudo npm install --save-dev gulp-compile-handlebars
Password:
npm WARN package.json path@0.4.9 path is also the name of a node core module.
gulp-compile-handlebars@0.2.0 node_modules/gulp-compile-handlebars
??? through2@0.4.2 (readable-stream@1.0.27-1, xtend@2.1.2)
??? handlebars@2.0.0-alpha.4 (optimist@0.3.7, uglify-js@2.3.6)
Cooldude-MacBook-Air:_overlay cooldude$ ls
gulpfile.js.old node_modules src
Run Code Online (Sandbox Code Playgroud)
我以前没见过 - 我该怎么做才能解决这个问题?
我想手动指定一个视图来显示某些节点.
我可以添加一个节点ID过滤器(例如,如果节点id = 50则显示),但我可以使多个过滤器变为"AND"'(例如,如果节点id = 50 AND节点= 51则显示).
我宁愿不必使用分类法或其他任何东西,因为我目前还没有使用它.如果是这样的话,只需手动编写视图输出就会更容易.
使用三元运算符需要两次调用该函数.
var colour = (tryAdventurousColour() != null) ? tryAdventurousColour() : 'black';
Run Code Online (Sandbox Code Playgroud)
可以在1行中完成吗?
编辑:修正语法编辑:像这样但更好
var color =((color = tryAdventurousColour())!= null)?颜色:'黑色';
我一直在玩画架,我发现演出开始下降.在我的示例中,Chrome需要大约3秒才能达到这一点,Safari需要25秒,Firefox就到处都是.
问题:
示例 为了演示我遇到的性能影响,我在循环中创建了一个简单的圆重绘动画,但帧速率很快就开始下降.如果我恢复到纯画布API调用,那么它将重新获得性能.
下面是我重绘的关键片段,它选择绘制圆圈的方法:
if ( counter.fps > 60) {
circle.graphics.beginFill('green')
circle.graphics.drawCircle(0,0, w / 10)
circle.graphics.endFill();
stage.update();
} else {
context.beginPath();
context.arc(circle.x, circle.y, w / 10, 0, 2 * Math.PI, false);
context.fillStyle = "darkred";
context.fill();
}
Run Code Online (Sandbox Code Playgroud)
有关演示,请参阅此jsfiddle:http: //jsfiddle.net/AshCoolman/5xYxM/9/
我尝试过类似结果的变化:
(粗略)性能时间表(2012年中期macbook air OSX 10.8.2)
Chrome v26.0.1410.43
Safari v6.0.2(8536.26.17)
Firefox v20
javascript ×6
babeljs ×2
ecmascript-6 ×2
gulp ×2
mocha.js ×2
canvas ×1
chai ×1
drupal ×1
drupal-6 ×1
easeljs ×1
git ×1
gulp-less ×1
karma-mocha ×1
mobx ×1
node.js ×1
react-native ×1
reactjs ×1
testing ×1
views ×1