我正在使用新的FireFox Addons SDK来开发扩展.我有一个小部件,附有一个面板.该面板用于控制首选项,因此我需要从面板的内容脚本中访问simple-storage api.我知道您无法直接访问API,因此我尝试使用消息传递.继承人我得到了什么:
exports.main = function() {
var panel = require('panel');
var ss = require('simple-storage');
var prefPanel = panel.Panel({
contentURL: self.data.url('prefPanel.html'),
contentScriptFile: self.data.url('prefPanel.js'),
contentScriptWhen: 'ready',
onMessage: function(message) {
switch(message.method) {
case 'setValue':
ss.storage[message.key] = message.value;
}
},
});
prefPanel.postMessage(ss.storage);
require('widget').Widget({
id: 'ml-pref-button',
content: 'ML',
width: 30,
panel: prefPanel,
})
}
Run Code Online (Sandbox Code Playgroud)
在prefPanel.js我有:
self.on('message', function(storage) {
storage.setValue = function(key, value) {
this[key] = value;
self.postMessage({
method: 'setValue',
'key': key,
'value': value,
});
}
// Do some stuff, using storage object
}); …Run Code Online (Sandbox Code Playgroud) 我认为按惯例,只有带感叹号的方法才会改变对象.
> array = [1, 2, 3]
=> [1, 2, 3]
> array.pop
=> 3
> array
=> [1, 2]
Run Code Online (Sandbox Code Playgroud)
为什么不是Array的pop调用的方法pop!?
我正在使用ffmpeg使用像这样的vfilter使用PNG文件为视频添加水印:
ffmpeg -i 26.wmv -vcodec libx264 -acodec copy -vf "movie=logo.png [watermark]; [in][watermark] overlay=10:10 [out]" 26_w.mkv
Run Code Online (Sandbox Code Playgroud)
但是,输入文件的质量/比特率都不同,我希望输出文件的质量/比特率与输入文件相似.我怎么做到这一点?另外,我对ffmpeg几乎一无所知,那么有没有什么选择可以提供良好的质量:文件大小比例?
我只是想知道在php中哪一个是快速的strpos()/ stripos()或preg_match()函数.
在javascript中,你可以做这样的事情
arr.map(function(val) {
return typeof val == 'array' ? val.map(arguments.callee) : val.doSomething();
});
Run Code Online (Sandbox Code Playgroud)
这将以递归方式迭代arr并应用于doSomething每个值.
在PHP中是否有与JavaScript的arguments.callee相同的东西?
在 Android.mk 文件中,我有以下执行 bash 脚本的行:
$(info $(shell ($(LOCAL_PATH)/build.sh)))
Run Code Online (Sandbox Code Playgroud)
但是,如果命令失败,则构建会继续而不是退出。
在这种情况下,如何使整个构建失败?
在负载事件http://api.jquery.com/load-event/的jQuery文档中,它说
Can cease to fire for images that already live in the browser's cache.有关此的更多信息,例如它影响的浏览器,以及在什么情况下?
var foo = 'bar';
console.log(window.foo); // bar
Run Code Online (Sandbox Code Playgroud)
似乎变量被赋值为属性this,但在匿名函数内部,this是指父作用域,但不将变量赋给父作用域.
function() {
var foo = 'bar';
}();
window.foo; // undefined
Run Code Online (Sandbox Code Playgroud)
变量在非全局范围内分配给什么对象?
我有一个包含以下JSON字符串的变量:
{
"0" : "Jun 20, 2012 03:02 PM",
"1" : "Jun 20, 2012 03:26 PM",
"2" : "Jun 21, 2012 01:12 PM",
"3" : "Jun 21, 2012 01:25 PM",
"4" : "Jun 21, 2012 02:42 PM",
"5" : "Jun 21, 2012 02:43 PM",
"6" : "NULL"
}
Run Code Online (Sandbox Code Playgroud)
我希望将此JSON转换为javascript中的数组,以便array [0]具有"Jun 20,2012 03:02 PM"数组[1]具有"Jun 20,2012 03:26 PM"等等.