我想知道我是否应该将游戏切换到requestAnimationFrame.如果还有理由再这样做了,正如我读到的那样,当你在主流浏览器中切换标签时,setTimeout()现在也会暂停.
无论如何,说我想控制动画的FPS.
目前我可以这样做:
k.state.loopinterval =
window.setInterval(renderLoop(), 1000 / k.settings.engine.fps );
Run Code Online (Sandbox Code Playgroud)
k.settings.engine.fps想要的fps 在哪里?
如果我这样做requestAnimationFrame,我就失去了这种可能性,它只会给我任何可以给予的东西:
window.requestAnimFrame(k.operations.startLoop);
renderLoop();
Run Code Online (Sandbox Code Playgroud)
我看到有人建议将requestAnimFrame放在另一个循环中:
setInterval( function () {
requestAnimationFrame( draw );
}, 1000 / 60 );
Run Code Online (Sandbox Code Playgroud)
那么......我该怎么办?保持原状?
requestAnimationFrame有什么好处,现在切换标签时setTimeout也暂停了?
Chrome始终会针对我的MJPEG流发出警告:
Resource interpreted as Image but transferred with MIME type multipart/x-mixed-replace
Run Code Online (Sandbox Code Playgroud)
是否可以使用更好的MIME类型来解决这个问题?我可以使用"图像",即使它是一个多部分流吗?
我的一位老同事在我们的代码中写道:
public function paginate() {
return $this->paginate;
}
Run Code Online (Sandbox Code Playgroud)
我想知道:这会返回函数paginate()还是类属性$ paginate?
我猜测后者,但奇怪的是我没有找到关于这个主题的任何信息.
我想散列一个简单的字符串数组文档说你不能简单地将字符串输入hashlib的update()函数,所以我尝试了一个常规变量,但后来我得到了TypeError: object supporting the buffer API required错误.
这是我到目前为止所做的
def generateHash(data):
# Prepare the project id hash
hashId = hashlib.md5()
hashId.update(data)
return hashId.hexdigest()
Run Code Online (Sandbox Code Playgroud) 对我正在写的某个班级来说,表现很重要.
我想过调用这样的函数:
debug('This is a debug message, only visible when debugging is on');
Run Code Online (Sandbox Code Playgroud)
内容就像
function debug(message) {
if (DEBUG) console.log(message);
}
Run Code Online (Sandbox Code Playgroud)
所以我想知道:如果DEBUG变量永远不变,V8是否足以将其标记为"死代码" ?
编辑:我更担心Node中的性能而不是浏览器,因此在缩小时删除代码是不够的.
Edit2:我从提议的解决方案中做了一个JSPerf基准测试,它们非常令人惊讶:http://jsperf.com/verbose-debug-loggin-conditionals-functions-and-no-ops/3
在我的文件中,lib/server.js我有以下代码:
/**
* My Test Server
*
* @typedef {Object} My.Server
* @prop {String} name
*/
function Server() {
this.name = 'zever';
}
Run Code Online (Sandbox Code Playgroud)
当我@typedef在同一个文件中引用它时,它可以工作:
但是,当我@typedef在同一个项目中的另一个文件中使用时,我什么也得不到:
(是的,我也在单行上尝试过jsdoc)
这里出了什么问题?
给出像#fff443或的字符串#999999
如何验证字符串是否包含:
我正在从mysql命令解析查询结果(使用--table参数)
local records=`echo "${query}" | $MYSQL -u $MyUSER -h $MyHOST -p$MyPASS --table`
Run Code Online (Sandbox Code Playgroud)
查询运行成功,我收到了很好的数据.
然后我迭代这些数据:
for data in $records ;
do
test+=$data
done
Run Code Online (Sandbox Code Playgroud)
代码更广泛,但基本上就是这样.Bash将每个空间视为分隔符,这对于文本字段来说是个问题.
所以我只是将它们连接起来.但是当我向bash提供这些数据时:
*URL*
host:
test.url.com
pass:
anothertest
http://www.test.com
Run Code Online (Sandbox Code Playgroud)
它将它连接到类似的东西:
pass:test.url.com.com
Run Code Online (Sandbox Code Playgroud)
好像它不是连接,而是覆盖.这可能是一些回车问题吗?
在Linux上使用Motion,每个网络摄像头都在其自己的端口上作为流提供.我现在想要使用Node.js在同一个端口上提供这些流.
app.get('/motion', function(req, res) {
var boundary = "BoundaryString";
var options = {
// host to forward to
host: '192.168.1.2',
// port to forward to
port: 8302,
// path to forward to
path: '/',
// request method
method: 'GET',
// headers to send
headers: req.headers
};
var creq = http.request(options, function(cres) {
res.setHeader('Content-Type', 'multipart/x-mixed-replace;boundary="' + boundary + '"');
res.setHeader('Connection', 'close');
res.setHeader('Pragma', 'no-cache');
res.setHeader('Cache-Control', 'no-cache, private');
res.setHeader('Expires', 0);
res.setHeader('Max-Age', 0);
// wait for data
cres.on('data', function(chunk){
res.write(chunk);
});
cres.on('close', function(){ …Run Code Online (Sandbox Code Playgroud) 所以,我想做这样的事情:
var a = 'a';
var dummy = function() {
// Print out var 'a', from the scope above
console.log('Dummy a: ' + a);
// Print out 'b', from the 'compelled' scope
console.log('Dummy b: ' + b);
}
(function() {
var b = 'otherscope';
// I know apply won't work, I also don't want to merge scopes
dummy.apply(this);
// I want something like this:
dummy.compel(this, [], {b: 'injected!'});
})();
Run Code Online (Sandbox Code Playgroud)
但那不行.
我实际上并不希望函数能够达到2个范围,我希望能够从外部设置虚函数内使用的'b'变量.
javascript ×4
node.js ×3
mjpeg ×2
bash ×1
dead-code ×1
debugging ×1
hash ×1
html5 ×1
jquery ×1
jsdoc ×1
md5 ×1
mime-types ×1
motion ×1
optimization ×1
php ×1
proxy ×1
python ×1
python-3.x ×1
regex ×1
settimeout ×1