我需要查看所有文件夹,包括当前的文件夹以进行更改.所以我用过
gulp.task('start', () => {
if (node) node.kill()
node = spawn('node', ['server.js'], {
stdio: 'inherit'
})
node.on('close', function(code) {
if (code === 8) {
gulp.log('Error detected, waiting for changes...');
}
});
});
gulp.watch(['./**/*.js'], ['start']);
gulp.task('default', ['start', 'watch']);
process.on('exit', function() {
if (node) node.kill()
});
Run Code Online (Sandbox Code Playgroud)
但它会导致100%的CPU使用率.如果我只在一个文件夹(包含99%的所有需要观看的文件)上使用它,比如'api/**/*.js`,几乎没有任何CPU使用.
我究竟做错了什么?
如何<LOCATION></LOCATION>在XML文件的标记之间提取"US_NY"之类的STRING ?我尝试使用FINDSTR,但换行是有问题的.
<?xml version="1.0" encoding="utf-16"?>
<DEVICE>
<AGENT>
<VERSION>
2.0.0.2
</VERSION>
<CONNECTION>
<LOCATION>
US_NY
</LOCATION>
<SERVERIP>
127.0.0.1
</SERVERIP>
<TCPPORT>
5656
</TCPPORT>
<POLLINTERVAL>
5
</POLLINTERVAL>
</CONNECTION>
</AGENT>
</DEVICE>
Run Code Online (Sandbox Code Playgroud) 我做了一个简单的弹出管理器,它使用dom来决定哪个弹出窗口应该在前面,没有任何z-index规则:当我点击一个弹出窗口时,它移动到第一个位置,所以它位于另一个弹出窗口的顶部.不幸的是:这个dom运动打破了弹出窗口中的onclick事件.
我做了一个简单的问题:下面的代码应该输出三个点击事件:mousedown,mouseup和click,它适用于Firefox,我认为它曾经用于以前版本的Chrome,但它不再存在.
<div>
<div onmousedown="console.log('mousedown');this.parentElement.appendChild(this);" onmouseup="console.log('mouseup');" onclick="console.log('click');">Click</div>
</div>Run Code Online (Sandbox Code Playgroud)
你知道我怎么能解决这个问题,并回到我的onclick事件?
我有一个关于JavaScript的问题.当我声明新变量并为其分配新的类实例时,如果抛出错误,则变量完全无法使用.
下面的代码应该抛出错误
class MyClass {
constructor (config) {
this.someProperty = config.someProperty || '';
}
}
let myClassInstance = new MyClass();
Run Code Online (Sandbox Code Playgroud)
如果我尝试为其分配内容,JavaScript将引发错误.
myClassInstance = '123'
未捕获的ReferenceError:未定义myClassInstance
然后我尝试定义变量
let myClassInstance = '123'
未捕获的SyntaxError:已声明标识符'myClassInstance'
变量也无法删除.我们可以用这个问题做些什么吗?我只是很好奇,当然我会处理将undefined作为配置传递给构造函数.
编辑:我也尝试使用var,然后我可以重用myClassInstance.我想知道为什么如果我使用let变量无法删除,声明或新值不能重新分配.
编辑2:我可以处理传递undefined或传递空对象.只是纯粹的好奇心在JS控制台中使用该变量会发生什么,如果您一次粘贴所有内容,代码将无法执行
function Name(first, last) {
this.first = first;
this.last = last;
this.fullName = first + " " + last
}
Name.prototype = {
get fullName() {
return this.first + " " + this.last;
},
set fullName(name) {
var names = name.split(" ");
this.first = names[0];
this.last = names[1];
}
};
var person = new Name("Foo", "Bar");
// person.fullName = "Foo Bar"
person.hasOwnProperty("fullName") // false
Run Code Online (Sandbox Code Playgroud)
有办法归还物业吗?
我的XSLT是带有xmlns:x="http://something"属性的一些标签...如何避免这个冗余属性?输出XML从不使用,既不在x:tag,也不在x:attribute.
XML示例:
<root><p>Hello</p><p>world</p></root>
Run Code Online (Sandbox Code Playgroud)
XSL的例子:
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xlink="http://www.w3.org/1999/xlink">
<xsl:output encoding="UTF-8" method="xml" version="1.0" indent="no"/>
<xsl:template match="root"><foo>
<xsl:for-each select="p">
<p><xsl:value-of select="." /></p>
</xsl:for-each></foo>
<xsl:for-each select="x">
<link xlink:href="{x}" />
</xsl:for-each></foo>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
XML输出示例:
<foo>
<p xmlns:xlink="http://www.w3.org/1999/xlink">Hello</p>
<p xmlns:xlink="http://www.w3.org/1999/xlink">world</p>
</foo>
Run Code Online (Sandbox Code Playgroud)
这xmlns:xlink是一个开销,它没有被使用!
XSLT必须使用命名空间但输出不是的典型情况:
<xsl:value-of select="php:function('regFunction', . )" />
Run Code Online (Sandbox Code Playgroud) 我们有一个XML数字,可以在一个大的XML文件中最多3个数字,必须转换为固定长度的文本,以便加载到另一个系统.
我需要在输出中用前导零填充这个长度为15(这是固定长度的文本)
例子:
- 1 becomes 000000000000001
- 11 becomes 000000000000011
- 250 becomes 000000000000250
Run Code Online (Sandbox Code Playgroud)
我试过这个:
<xsl:value-of select="substring(concat('000000000000000', msg:BankAccount/msg:Counter), 12, 15)"/>
Run Code Online (Sandbox Code Playgroud)
在开头获取15个零并获取子字符串,但我必须在子字符串中犯了一个错误,因为在结果中我得到了
0000000000000000000000009LLOYDS BANK PLC
00000000000000000000000010LLOYDS BANK PLC
Run Code Online (Sandbox Code Playgroud)
我也试过,format-number但它返回NaN
<xsl:value-of select="format-number(msg:BankAccount/msg:Counter, '000000000000000')"/>
Run Code Online (Sandbox Code Playgroud)
返回'NaN'
那么我做错了什么,最好的办法是什么?
作为我学习JavaScript的一部分,我尝试编写代码来演示我正在学习的概念; 今天我正在学习悬挂变量.这是我写的代码:
console.log("A: My name is " + name);
function happy() {
console.log ("1: I am " + feeling);
var feeling = "happy";
console.log ("2: I am " + feeling);
}
happy();
var name = "Jim";
console.log("B: My name is " + name);
Run Code Online (Sandbox Code Playgroud)
我期待以下结果:
A: My name is undefined
1: I am undefined
2: I am happy
B: My name is Jim
Run Code Online (Sandbox Code Playgroud)
但是,在WriteCodeOnline.com和另一个沙箱中测试我的代码时,会显示第一个console.log A: My name is.我使用的是Chrome浏览器,如果有所不同的话.
所以,我的问题是,为什么函数中提升的局部变量返回undefined而提升的全局变量返回空白?
当我想在我的字符串开关case语句中使用冒号":"时,我得到错误"unterminated string literal",我该如何解决这个问题,为什么会出错?
码:
@switch (stringText)
{
case "aaaa:ggg":
Do something...
break;
case "bbbb:ggg":
Do something else...
break;
}
Run Code Online (Sandbox Code Playgroud)
如果通过这样做修复它,但是没有找到它是一个好的解决方案:
const string extra = ":ggg";
@switch (stringText)
{
case "aaaa" + extra:
Do something...
break;
case "bbbb" + extra:
Do something else...
break;
}
Run Code Online (Sandbox Code Playgroud)
编辑:使用MVC Razor语法
我正在阅读Javascript原型属性如何与继承一起工作,然后开始查看Angular.js代码并提出了一些问题.
首先,我读到prototype属性指向一个具有"constructor"属性的对象,该属性指向用于创建对象的原始函数.例如:
// This is the constructor
function Shape() {
this.position = 1;
}
// The constructor points back to the original function we defined
Shape.protoype.constructor == Shape;
Run Code Online (Sandbox Code Playgroud)
原型还包含由我们或Javascript语言本身定义的任何其他方法或属性,并且这些方法或属性由对象的所有实例共享.如果你想让一个名为Square的对象继承自Shape,你需要设置Square的原型等于Shape的一个新实例,因为Square.prototype的内部[[prototype]]属性被设置为Shape.prototype属性的公共对象值. .
function Square() {}
Square.prototype = new Shape();
var square = new Square();
square.position; // This will output 1
Run Code Online (Sandbox Code Playgroud)
这一切都对我有意义.
但是,我有一个问题的Angular.js代码似乎与所有这些相关,但做了一件我不理解的事情.它似乎没有处理继承,所以我可以理解为什么会有差异,但我只是好奇为什么他们按照他们的方式编写它.
在Angular.js中,有一个HashMap对象和一个Lexer对象,但它们的定义不同,但似乎是以相同的方式实例化和使用.首先定义Lexer构造函数,然后将原型设置为包含应由Lexer的所有实例共享的方法的对象文字.这一切都有道理.我不明白的是为什么他们指定"构造函数"属性并将其设置为"Lexer",而不是下面的HashMap.
var Lexer = function(options) {
this.options = options;
};
// Notice they specify Lexer as the constructor even though they don't for HashMap below
Lexer.prototype = {
constructor: Lexer, …Run Code Online (Sandbox Code Playgroud) javascript ×6
xml ×2
angularjs ×1
batch-file ×1
c# ×1
class ×1
ecmascript-6 ×1
gulp ×1
hoisting ×1
html ×1
inheritance ×1
let ×1
msxml6 ×1
node.js ×1
output ×1
razor ×1
undefined ×1
variables ×1
xslt ×1
xslt-1.0 ×1