小编Jon*_*com的帖子

当表达式不可能为TRUE时,表达式的计算结果为TRUE,是吗?

我有以下检查,看看是否应该将元素视为"悬停".

我很困惑,因为我看到元素设置为state === 'hover'不应该的时候.

alert消息更令人困惑,因为它告诉刚刚评估为true的表达式是不应该的表达式(如果您在逻辑上考虑它).

if( (ig.gui.cursor.pos.x >= element.pos.x) 
    && (ig.gui.cursor.pos.x <= element.pos.x + element.size.x)
    && (ig.gui.cursor.pos.y >= element.pos.y) 
    && (ig.gui.cursor.pos.y <= element.pos.y + element.size.y) 
    && !element.disabled ) {

    state = 'hover';

    alert(

        'This statement evaluates to true: '

        + ig.gui.cursor.pos.x
        + '>='
        + element.pos.x
        + '&&'
        + ig.gui.cursor.pos.x
        + '<='
        + element.pos.x
        + '+'
        + element.size.x
        + '&&'

        + ig.gui.cursor.pos.y
        + '>='
        + element.pos.y
        + '&&'
        + ig.gui.cursor.pos.y
        + '<='
        + element.pos.y
        + '+'
        + …
Run Code Online (Sandbox Code Playgroud)

javascript evaluation logic expression operator-precedence

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

如何列出 IPFS 实例的所有当前固定文件?

根据https://docs.ipfs.io/guides/concepts/pinning/,运行命令ipfs add hello.txt显然“固定”了文件“hello.txt”,但是为什么我在运行命令时没有看到后面列出的文件ipfs files ls? 它只列出我使用 IPFS 桌面应用程序添加的文件。为什么“hello.txt”现在不在列表中?

此外,我通过运行命令找到了一个所谓的“固定”对象列表ipfs pin ls,但是显示在那里的 CID 都没有对应于“hello.txt”,甚至没有任何前面提到的使用 IPFS 桌面添加的文件应用程序。

如何实际管理固定文件?

ipfs

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

如何在画布中的非alpha像素周围手动添加边框时提高速度

我写了一个脚本,它采用像这样的图像(通常黑色是alpha):

字形

...并添加您喜欢的任何颜色的边框:

带边框的字体

然而,它不是很快.创建边框图层需要大约130毫秒作为这种小字体的画布.更大的字体需要更长的时间!

逻辑很简单:

/* This is more or less psuedo-code. */

// Blank image data where I will put the border.
var newData = newContext.getImageData(0, 0, canvas.width, canvas.height);

// The image I will be analyzing.
var oldData = oldContext.getImageData(0, 0, this.data.width, this.data.height);

// Loop through every pixel in oldData and remember where non-alpha pixels are.
var fontPixels = this._getNonAlphaPixels(oldData);

// Loop through relevant pixels, remember neighboring pixels, and add border.
for (var px in fontPixels) {
    for …
Run Code Online (Sandbox Code Playgroud)

javascript canvas

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

NodeJS的'http'对象应该有一个名为get()的方法,但它在哪里呢?

我想在我的控制台中看到"得到回复"或"得到错误".

我一直在尝试使用http.get()执行HTTP请求,但是当我尝试时出现以下错误.

D:\wamp\www\Chat\server\test.js:19
http.get("http://google.com", function(res) {
     ^
TypeError: Object #<Server> has no method 'get'
    at Object.<anonymous> (D:\wamp\www\Chat\server\test.js:19:6)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)
Run Code Online (Sandbox Code Playgroud)

这是test.js的全部内容:

var http = require('http').createServer(handler);

var fs = require('fs');

http.listen(9090);

function handler(req, res) {
    fs.readFile(__dirname + '/index.html', function(err, data) {
        if (err) {
            res.writeHead(500);
            return res.end('Error loading index.html');
        }

        res.writeHead(200);
        res.end(data);
    });
}

http.get("http://google.com", function(res) {
    console.log("Got response: " + res.statusCode);
}).on('error', function(e) …
Run Code Online (Sandbox Code Playgroud)

javascript http node.js http-request

0
推荐指数
1
解决办法
541
查看次数