小编lev*_*evi的帖子

网站热图如何获得准确的数据?

有像crazyegg.com这样的服务可以向您显示访问者在您的网页上放置鼠标光标的位置.我的问题是,鉴于人们有不同的屏幕宽度,他们怎么能确定我的x坐标与另一个人x坐标在页面上的位置相同?意思是,两个人可能有相同的鼠标x坐标,但由于屏幕的宽度不同,他们的鼠标将位于网页的不同部分.

如何创建一个考虑到这一点的网页热图服务,并且可以在不同内容大小的多个不同网站上进行缩放和使用?

javascript analytics heatmap

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

为什么这种关闭工作?

假设我有一个简单的函数来警告消息:

function callMessage(msg){
        alert(msg);
    }
Run Code Online (Sandbox Code Playgroud)

现在,当我这样称呼它时,它不起作用.引发错误"嘿未定义"

function sayHi(){
        var hey = "hi there"
        setTimeout("callMessage(hey)", 1000);
    }
    sayHi();
Run Code Online (Sandbox Code Playgroud)

但是当我在一个匿名函数中调用它时它确实有效:

function sayHi(){
        var hey = "hi there"
        setTimeout(function(){callMessage(hey);}, 1000);
    }
    sayHi();
Run Code Online (Sandbox Code Playgroud)

为什么"hey"变量只有在我将其放入匿名函数时才可见?

javascript closures

8
推荐指数
2
解决办法
275
查看次数

"这个"在一个匿名函数里面?

在John Resig的书"Pro Javascript技术"中,他描述了一种使用以下代码生成动态对象方法的方法:

// Create a new user object that accepts an object of properties
function User(properties) {
    // Iterate through the properties of the object, and make sure
    // that it's properly scoped (as discussed previously)
    for (var i in properties) {
        (function() {
            // Create a new getter for the property
            this["get" + i] = function() {
                return properties[i];
            };
            // Create a new setter for the property
            this["set" + i] = function(val) {
                properties[i] = val;
            }; …
Run Code Online (Sandbox Code Playgroud)

javascript anonymous-function

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

使用Mocha和Chai捕获超出范围的错误

我正在修改node.js库以支持真正的异步操作.

我和Mocha和Chai在制作这个(类似的)测试通过时遇到了麻烦.

it('should throw an error', function() {
    expect(function() {
        process.nextTick(function() {
            throw new Error('This is my error');
        });
    }).to.throw(Error);
});
Run Code Online (Sandbox Code Playgroud)

问题是 - 由于nextTick - 错误被抛出范围,it除了测试失败之外,Mocha还输出以下内容.

Uncaught Error: This is my error
Run Code Online (Sandbox Code Playgroud)

构建此测试以使其成功的正确方法是什么?

javascript mocha.js node.js chai

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

SQLite多个自动增量列?

我有以下SQL我试图用来创建一个表和一些列.作为其中的一部分,我希望其中两列自动增加整数.当我尝试使用下面的代码时,它给了我一个错误.

    CREATE TABLE IF NOT EXISTS 'tasks' (
'rowID' INTEGER, 
'gID' INTEGER, 
'task' TEXT, 
'status' TEXT, 
'position' INTEGER, 
'updated' INTEGER, 
'inlist' TEXT, 
'deleted' TEXT, 
PRIMARY KEY AUTOINCREMENT ('rowID','position')
)
Run Code Online (Sandbox Code Playgroud)

当我从SQL中删除关键字"AUTOINCREMENT"时,它可以正常工作.

是否可以有两个自动增量柱?如果没有,有没有一种方法可以让一个列自动从另一个(自动递增)列中取出值,因为它被插入?

谢谢

sql sqlite insert auto-increment

5
推荐指数
2
解决办法
4165
查看次数

为什么Function.x在声明Function.prototype.x后工作?

据我所知,Function的prototype属性是如何向从该函数实例化的所有对象添加方法/属性.

所以,当我尝试这样的事情

function Person(){}
Person.prototype.saySomething = function(){ alert( "hi there" ); }

Person.saySomething();
Run Code Online (Sandbox Code Playgroud)

我得到错误"Person.saySomething不是一个函数",这是有意义的,因为我没有在Person对象实例上执行该函数.

但为什么运行以下代码工作呢?

Function.prototype.sayHi = function(){ alert( "hi!" );}

Function.sayHi();
Run Code Online (Sandbox Code Playgroud)

javascript prototype

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