我想确认一个值是十进制(或0),因此该数字应大于或等于零且小于1.
describe('percent',function(){
it('should be a decimal', function() {
var percent = insights.percent;
expect(percent).toBeGreaterThan(0);
expect(percent).toBeLessThan(1);
});
});
Run Code Online (Sandbox Code Playgroud)
我如何模仿"> = 0"?
我知道如何将服务注入组件(通过@Component),但是如何使用DI来传递组件之外的服务?
换句话说,我不想这样做:
export class MyFirstSvc {
}
export class MySecondSvc {
constructor() {
this.helpfulService = new MyFirstSvc();
}
}
export class MyThirdSvc {
constructor() {
this.helpfulService = new MyFirstSvc();
}
}
Run Code Online (Sandbox Code Playgroud) 例如,我想这样做:
if ($http_user_agent ~ "MSIE 6.0" || $http_user_agent ~ "MSIE 7.0" (etc, etc)) {
rewrite ^ ${ROOT_ROOT}ancient/ last;
break;
}
Run Code Online (Sandbox Code Playgroud)
而不是这个:
if ($http_user_agent ~ "MSIE 6.0") {
rewrite ^ ${ROOT_ROOT}ancient/ last;
break;
}
if ($http_user_agent ~ "MSIE 7.0") {
rewrite ^ ${ROOT_ROOT}ancient/ last;
break;
}
Run Code Online (Sandbox Code Playgroud)
Nginx拒绝这种语法(减去(等等)),我在文档中没有看到任何关于此的内容.提前致谢.
此外,我们选择不使用$ ancient_browser指令,因此这不是一个选项.
作为我正在编写的小程序的一部分,我想使用gulp将大量文件转换为markdown.这不是与程序分开的构建步骤的一部分.这是该计划的一部分.所以我没有使用gulpfile来处理这个问题.
问题是,因为它是异步的,我想使用一个在gulp任务完成时会提醒我的promise.
这样的事情是理想的:
io.convertSrc = function() {
var def = q.defer();
gulp.src(src + '/*.md')
.pipe(marked({}))
.pipe(gulp.dest(dist), function() {
def.resolve('We are done!');
});
return def.promise;
}
Run Code Online (Sandbox Code Playgroud)
但是pipe不接受回调.我怎么能处理这个?谢谢你的帮助,我有点新意.
我正在尝试升级JavaScript(我在工作中没有使用它),并且很好地包围了Constructor函数以及如何实例化从它们继承属性的新对象.
但通常要真正学到一些东西,我需要在我正在研究的实际项目中使用它并在行动中看到它.
问题是,我正在阅读的所有内容都使用这些示例来解释继承:
function Apple (type) {
this.type = type;
this.color = "red";
this.getInfo = getAppleInfo;
}
Run Code Online (Sandbox Code Playgroud)
要么
function Car( model, year, miles ) {
this.model = model;
this.year = year;
this.miles = miles;
this.toString = function () {
return this.model + " has done " + this.miles + " miles";
};
}
Run Code Online (Sandbox Code Playgroud)
要么
function makeBaby(parent, name) {
var baby = Object.create(parent);
baby.name = name;
return baby;
}
Run Code Online (Sandbox Code Playgroud)
正如您可能想象的那样,这些例子(水果,汽车和父母)对于学习概念的目的肯定是有帮助的,但实际上并没有将它们付诸实践.
有没有人举例说明原型继承如何在生产级Web应用程序中起作用?
在克里斯科伊尔的帖子的启发下,我决定放弃咕噜咕噜.但是我在设置方面遇到了很大的问题.
首先,我安装了Node.
然后我将package.json文件添加到我的项目根目录,包括:
{
"name": "example-project",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.1"
}
}
Run Code Online (Sandbox Code Playgroud)
然后我跑了 npm install
最后,我跑了 npm install -g grunt-cli
它带来了大量的错误:
npm http GET https://registry.npmjs.org/grunt-cli
npm http 304 https://registry.npmjs.org/grunt-cli
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/grunt-cli'
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules/grunt-cli']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules/grunt-cli',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/grunt-cli',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR! '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53', …Run Code Online (Sandbox Code Playgroud) 大多数时候,我使用带有预设断点的LESS变量进行媒体查询,如下所示:
@s-max : ~"screen and (max-width: 40em)";
@m-max : ~"screen and (max-width: 50em)";
@l-max : ~"screen and (max-width: 60em)";
USAGE
.some-class {
color: red;
@media @s-max {
color: blue;
}
}
Run Code Online (Sandbox Code Playgroud)
但有时,我希望能够在我的.less样式表中引用任意断点,而无需在单独的mixin文件中设置新的预设值.
你可以在SASS中做到这一点.mixin看起来像这样:
@mixin bp-min($canvas) {
@media only screen and (min-width:$canvas) {@content;}
}
USAGE
@include bp-min(750px) {
//responsive styling for min-width of 750px
}
Run Code Online (Sandbox Code Playgroud)
在LESS中,我想象等效的mixin看起来像这样:
.bp-min(@min) {
@media only screen and (min-width:@min)...
}
Run Code Online (Sandbox Code Playgroud)
唯一的问题是,LESS中缺少{@content}参数,它抓住了开发人员输入的其余样式.我喜欢SASS,但我不能在工作中使用它.
有谁知道这个问题的基于LESS的解决方案?
当用户从iPhone/iPad登录我的应用程序时,Safari(有用)会在用户填写用户名/密码字段时放大.但是当提交表单并将其登录时,我们不会重新加载页面(这是单页面应用程序),因此不会重置缩放.所以应用程序总是以放大的比例开始.
我查看了Jeremy Keith的解决方案,该解决方案成功地重置了缩放,但也阻止了用户将来进行缩放/缩放,因为他设置maximum-scale了视口.
像这样:
var viewportmeta = document.querySelector('meta[name="viewport"]');
if (viewportmeta) {
viewportmeta.content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0';
}
Run Code Online (Sandbox Code Playgroud)
有没有人看到一个很好的解决方案,在表单提交后重新设置,之后没有冻结视口?
我希望我的服务器每分钟都执行一个节点脚本.如果我手动执行文件(./main.js),程序执行完美,所以我很确定这不是问题.但当我把它交给cron来执行时,没有任何反应.
这是cron文件中的行.
*/1 * * * * /home/bryce/scripts/wudu/main.js
这是一个示例日志:
Oct 11 15:21:01 server CROND[2564]: (root) CMD (/home/bryce/scripts/wudu/main.js)
可执行文件: home/bryce/scripts/wudu/main.js
#!/usr/bin/env node
var program = require('commander');
var v = require('./cli/validation');
var a = require('./cli/actions');
program
.version('0.0.1')
.option('-u, --url', 'Register url')
.option('-s, --selector', 'Register selector')
.option('-p, --pagination', 'Register pagination')
.option('-i, --index', 'Pass an index, to destroy')
.parse(process.argv);
var args = process.argv.slice(2),
mode = v.mode(args[0]),
options = v.hasArgs(mode, program);
a.init(mode, options);
Run Code Online (Sandbox Code Playgroud)
知道为什么我会收音机沉默吗?在其他地方我应该调试?
更新:
我认为问题与我的相对文件路径有关,而main.js是从它自己的目录外执行的.
所以现在,我已经放在exe.sh了wudu目录中.它看起来像这样:
#!/bin/bash
cd …Run Code Online (Sandbox Code Playgroud) 在一个指令中,我想在我执行某个函数之前检查一个元素是否有一个属性.但是我在jqLite文档中没有看到任何内容.
例如:
.directive('noReadonly', function() {
return {
link: function($scope, $element, $attr, ctrl) {
$element.on('focus', function() {
if ($element.hasAttribute('readonly'))
$element.removeAttr('readonly');
});
},
}
})
Run Code Online (Sandbox Code Playgroud)