小编Luk*_*rns的帖子

异步构造函数

我怎样才能最好地处理以下情况?

我有一个构造函数需要一段时间才能完成.

var Element = function Element(name){
   this.name = name;
   this.nucleus = {};

   this.load_nucleus(name); // This might take a second.
}

var oxygen = new Element('oxygen');
console.log(oxygen.nucleus); // Returns {}, because load_nucleus hasn't finished.
Run Code Online (Sandbox Code Playgroud)

我看到三种选择,每种选择都与众不同.

,向构造函数添加回调.

var Element = function Element(name, fn){
   this.name = name;
   this.nucleus = {};

   this.load_nucleus(name, function(){
      fn(); // Now continue.
   });
}

Element.prototype.load_nucleus(name, fn){
   fs.readFile(name+'.json', function(err, data) {
      this.nucleus = JSON.parse(data); 
      fn();
   });
}

var oxygen = new Element('oxygen', function(){  
   console.log(oxygen.nucleus);
});
Run Code Online (Sandbox Code Playgroud)

,使用EventEmitter发出'loaded'事件.

var …
Run Code Online (Sandbox Code Playgroud)

javascript constructor asynchronous node.js

51
推荐指数
2
解决办法
2万
查看次数

使用jQuery进行多行字符串插入

$("#addSelect").click(function() {
        $("#optionsForm").after("Hello world.");
} );
Run Code Online (Sandbox Code Playgroud)

这有效.

$("#addSelect").click(function() {
        $("#optionsForm").after("<tr>
    <td><input type="text" class="optionField" value="Options" /></td>
    <td>
        <ul class="option">
            <li><select><option>Value..</option></select></li>
        </ul>
    </td>
</tr>");
} );
Run Code Online (Sandbox Code Playgroud)

这样的事情没有.

在Chrome中,我收到错误" Unexpected token ILLEGAL ".谷歌搜索后,我发现我的小脑对javascript和多行知之甚少.所以我在每一行的末尾添加了'\'.然而,我现在得到错误" 意外的标识符 ".

我想这不会像我做的那样困难:)

javascript jquery

28
推荐指数
3
解决办法
4万
查看次数

节点中的椭圆曲线门限密码学

我想在javascript中使用椭圆曲线加密来实现类似于双人规则的东西.

编辑:我基本上在寻找像比特币multisig这样的东西.

所以我需要结合使用两个公钥来获得一个组合密钥,它需要两个私钥才能生成签名.请参阅https://crypto.stackexchange.com/questions/25250/adding-two-public-keys.

我怎么能在节点中这样做?

javascript cryptography elliptic-curve node.js

11
推荐指数
1
解决办法
1508
查看次数

强制关注一个具有异常的元素.(jQuery的)

我有两个输入字段.我想强调关注#area,无论用户点击哪里,除非它在#input上.我尝试过类似的东西,但由于输入是文档的一部分,它不起作用.

$("#area").focus();
$(document).click(function() { $("#area").focus() };
$("#input").click(function() { $("#input").focus() };
Run Code Online (Sandbox Code Playgroud)

思考?

jquery focus input

7
推荐指数
1
解决办法
2万
查看次数

ExpressJS:如何忽略路由中的公共静态文件?

app.get("/:name?/:group?", function(req, res){...
Run Code Online (Sandbox Code Playgroud)

匹配我公共目录中的文件.所以,如果我包含样式表:

<link type="text/css" href="/stylesheets/style.css" />
Run Code Online (Sandbox Code Playgroud)

节点将匹配/stylesheets/style.css并指定名称样式的style.css.

避免这种情况的最佳方法是什么?

static public match node.js express

7
推荐指数
1
解决办法
6297
查看次数

Magento - 关于客户更新的"SQLSTATE [23000]:完整性约束违规..."

迁移服务器后,每次尝试更新客户信息时都会收到错误消息.我正在使用客户激活插件,但在禁用它后,我仍然得到相同的错误.

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '7-127' for key 2
Run Code Online (Sandbox Code Playgroud)

怎么了?

即使在卸载插件后,我在尝试保存客户信息时也会收到此错误消息.所以这让我相信它与Magento和/或我切换到的服务器有更大的问题.

我检查了Magento的日志,我多次收到此通知:

ERR (3): User Notice: Sorry, your PCRE extension does not support UTF8 which is needed for the I18N core  in ../httpdocs/store/lib/Zend/Locale/Format.php on line 769
Run Code Online (Sandbox Code Playgroud)

这有关系吗?

mysql sql magento mysql-error-1062

5
推荐指数
1
解决办法
5460
查看次数

使用 FFMPEG 将 Live Photo 元数据写入视频

根据Apple Live Photo 文件格式,JPEG 和 MOV 需要写入三部分元数据才能被接受为实时照片。我可以使用 exiftool 和 ffmpeg 编写必要的内容标识符元数据。

\n

对于 JPEG:

\n
exiftool -TagsFromFile reference.jpeg -makernotes -ContentIdentifier image.jpeg\nexiftool -ContentIdentifier="$id" image.jpeg\n
Run Code Online (Sandbox Code Playgroud)\n

同样,ffmpeg 可用于写入具有匹配 id 的顶级 Quicktime 元数据。

\n

但是我在定时元数据方面遇到了麻烦:["com.apple.quicktime.still-image-time" : 0xFF]

\n

我什至无法使用 ffmpeg 生成现有实时照片 MOV 文件的副本,以保留必要的定时元数据。

\n
ffmpeg -i original.mov -map 0 -c copy -movflags use_metadata_tags copy.mov\n
Run Code Online (Sandbox Code Playgroud)\n

复制全局元数据(即 com.apple.quicktime.content.identifier),但丢失必要的静态图像时间,可以使用 exiftool 确认:

\n
> exiftool -G -U -ee original.mov | grep \'Still Image Time\'\n[QuickTime]     Still Image Time                : -1\n> exiftool -G -U …
Run Code Online (Sandbox Code Playgroud)

metadata ffmpeg apple-live-photos

5
推荐指数
1
解决办法
1113
查看次数

Clone a function in Julia

I want to overwrite a function in Julia using its old definition. It seems the way to do this would be to clone the function and overwrite the original using the copy — something like the following. However, it appears deepcopy(f) just returns a reference to f, so this doesn't work.

f(x) = x
f_old = deepcopy(f)
f(x) = 1 + f_old(x)
Run Code Online (Sandbox Code Playgroud)

How can I clone a function?

Background: I'm interesting in writing a macro @override that allows me …

julia

4
推荐指数
1
解决办法
183
查看次数

Javascript中字符串的第一个单词的位置

我最初使用indexOf来查找空格,但我想找到任何单词边界.

像这样的东西,但是什么正则表达式?

var str = "This is a sentence",
firstword = str.search("");
return word;
Run Code Online (Sandbox Code Playgroud)

我想要回复"这个".即使在制表符,句号,逗号等的情况下也是如此.

javascript regex string position cpu-word

3
推荐指数
1
解决办法
4945
查看次数

使用javascript查找<textarea>的当前行的值

如何找到textarea当前行的值?

我知道我必须找到插入符号的位置,然后找到它之前的所有内容直到最后\n以及它之后的所有内容到下一个\n.

我怎样才能做到这一点?

javascript jquery textarea newline

2
推荐指数
1
解决办法
5196
查看次数