我想做什么
describe('my object', function() {
it('has these properties', function() {
expect(Object.keys(myObject)).toEqual([
'property1',
'property2',
...
]);
});
});
Run Code Online (Sandbox Code Playgroud)
但是当然会Object.keys返回一个数组,根据定义它是有序的...我更喜欢这个测试通过而不管属性排序(这对我来说很有意义,因为无论如何都没有对象键排序的规范......(至少直至ES5)).
如何验证我的对象具有它应该具有的所有属性,同时还要确保它没有丢失任何属性,而不必担心以正确的顺序列出这些属性?
当我列出预设时,订单是否重要?
换句话说,以下.babelrc文件是等效的吗?
.babelrc #1
{
"presets": ["es2015", "stage-2", "react"]
}
Run Code Online (Sandbox Code Playgroud)
.babelrc #2
{
"presets": ["react", "stage-2", "es2015"]
}
Run Code Online (Sandbox Code Playgroud) 我最近添加了eslint规则no-param-reassign.
但是,当我reduce用来构建一个对象(空对象initialValue)时,我发现自己需要accumulator在每次回调迭代时修改(回调函数的第一个arg),这会引起一个no-param-reassignlinter投诉(正如人们所期望的那样).
const newObject = ['a', 'b', 'c'].reduce((result, item, index) => {
result[item] = index; // <-- causes the no-param-reassign complaint
return result;
}, {});
Run Code Online (Sandbox Code Playgroud)
是否有更好的方法来构建一个reduce不修改accumulator参数的对象?
或者我应该简单地在reduce回调函数中禁用该行的linting规则?
所以我尝试在foursquare上实现结果:https://foursquare.com/explore?cat = drink & elode = url & near = Paris当你在地图上标记时,它滚动浏览右边列出的餐馆屏幕的一面到特设餐厅,并通过CSS突出显示.相反,当您点击列表中的餐厅时,它会在地图上突出显示它.
我正在使用skobbler /传单.我想我可以通过动态修改CSS来实现这一点,如下例所示:http://jsfiddle.net/gU4sw/7/ +页面中已经存在的目标脚本滚动.
然而,要实现这一点,看起来我需要在标记内分配一个ID(下面的2个标记):
var marker = L.marker([52.52112, 13.40554]).addTo(map);
marker.bindPopup("Hello world!<br>I am a popup1.", { offset: new L.Point(-1, -41) }).openPopup();
var marker = L.marker([52.53552, 13.41994]).addTo(map);
marker.bindPopup("Hello world!<br>I am a popup2.", { offset: new L.Point(-1, -41) }).openPopup();
Run Code Online (Sandbox Code Playgroud)
问题是:如何在html页面中的相应元素中指定标记ID来触发css更改?
我对JS的了解非常有限,但可能有一个很好的解决方案,那就是
我有一个功能
var data = {};
var myFunc = function() {
data.stuff = new ClassName().doA().doB().doC();
};
Run Code Online (Sandbox Code Playgroud)
我想测试doA,doB和doC全部调用.
我试图监视像这样的实例方法
beforeEach(function() {
spyOn(ClassName, 'doA');
};
it('should call doA', function() {
myFunc();
expect(ClassName.doA).toHaveBeenCalled();
});
Run Code Online (Sandbox Code Playgroud)
但那只是给了我一个"doA()方法不存在"的错误.
有任何想法吗?
我想克隆一个特定的分支.我不想下载master分支机构.
如何克隆整个项目然后切换到validations分支?
查看ES6 Object.assign 和Lodash _.assign的文档,看起来这些功能完全相同.
这是正确的理解吗?或者我错过了什么?
在过去,我使用了揭示模块模式.
function myModule() {
function foo() ...
function bar() ...
return {
foo: foo,
bar: bar
};
}
Run Code Online (Sandbox Code Playgroud)
使用ES6,这可以通过对象速记得到改进.
function myModule() {
function foo() ...
function bar() ...
return { foo, bar };
}
Run Code Online (Sandbox Code Playgroud)
现在有了内置的模块语法,我很难找到与上面最相似的首选模式.
选项#1命名为exports
// export file
function foo() ...
function bar() ...
export { foo, bar };
// import file
import { foo, bar } from './export-file';
foo();
bar();
Run Code Online (Sandbox Code Playgroud)
选项#2默认导出/导入与解构
// export file
function foo() ...
function bar() ...
export default { foo, bar }; …Run Code Online (Sandbox Code Playgroud) 使用OpenLayers 3,如何确定球形墨卡托(SRID:3857)投影中两点之间的距离?
我知道这distanceTo是在OpenLayers 2中使用的
point1.distanceTo(point2)
Run Code Online (Sandbox Code Playgroud)
我查看了OpenLayers 3文档,但我找不到类似的东西......
是否需要为Angular 2学习TypeScript?
Angular 2可以与纯JavaScript一起使用吗?
编辑:我已经看到用作ES6,ES7,Dart的语言编译为JavaScript要执行,但我还没有看到任何直接使用ES5 JavaScript的参考.
javascript ×8
ecmascript-6 ×2
jasmine ×2
angular ×1
babeljs ×1
bitbucket ×1
css ×1
ecmascript-5 ×1
es6-modules ×1
eslint ×1
git ×1
git-svn ×1
github ×1
html ×1
leaflet ×1
lodash ×1
maps ×1
openlayers-3 ×1