小编fco*_*tes的帖子

未捕获的TypeError:javascript中的非法调用

我正在创建一个lambda函数,它使用具体的params执行第二个函数.这个代码适用于Firefox,但不适用于Chrome,它的检查器显示一个奇怪的错误,Uncaught TypeError: Illegal invocation.我的代码出了什么问题?

var make = function(callback,params){
    callback(params);
}

make(console.log,'it will be accepted!');
Run Code Online (Sandbox Code Playgroud)

javascript lambda functional-programming invocation

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

min-width和max-width具有相同的值?

在过去,我看到了下一个CSS,我在想是否存在一些实际的区别

min-width: 90px;
max-width: 90px;
Run Code Online (Sandbox Code Playgroud)

width: 90px;
Run Code Online (Sandbox Code Playgroud)

css width

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

尝试/捕捉茉莉花

我有一个函数,它试图将参数解析为JSON对象.如果失败,则使用后备.

解析-code.js

function parseCode(code) {
    try {
        usingJSONFallback(code);
    } catch() {
        usingStringFallback(code);
    }
}

function usingJSONFallback(code) {
    JSON.parse(code);
    //...more code here
}

function usingStringFallback(code) {
   //... more code here
}
Run Code Online (Sandbox Code Playgroud)

main.js

//Some code...
parseCode('hello world!');
Run Code Online (Sandbox Code Playgroud)

我在这段代码中没有看到任何问题.但是,当我尝试为'catch'情况添加一些单元测试(使用Jasmine 2.3)时,Jasmine会自己捕获JSON解析错误并中止测试:

例如,对于Jasmine测试,例如:

describe('parseCode', function() {
    it('Parses a string', function() {
        var code = 'My code without JSON';
        expect(parseCode(code)).toThrow();
    });
});
Run Code Online (Sandbox Code Playgroud)

甚至像以下一样的测试:

describe('usingJSONFallback', function() {
   it('Throw an error if there is a string', function() {
      var code = 'My code without JSON';
      expect(usingJSONFallback(code)).toThrow();
   });
}); …
Run Code Online (Sandbox Code Playgroud)

javascript json unit-testing jasmine karma-jasmine

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

char*大小与malloc之后的预期不同

我已经创建了下一个获取char*的代码,但是在执行此代码之后,finalResult的大小比预期的大,有一些垃圾字符.为什么??我该如何解决?

//returns void
void processChar(){
            //.... more stuff here
            // init is a previous char*
            char* end = strstr(init,"</div>");
            if(end != NULL){
                    long length = strlen(init) - strlen(end);
                    if (length > 0){
                            char* finalResult = malloc(length);
                            strncat(finalResult, init,length);
                            //these lengths are different,being strlen(finalResult) > length
                            NSLog(@"%d %d",strlen(finalResult),length);
                            //... more stuff here  
                    }
            }
            return;
}
Run Code Online (Sandbox Code Playgroud)

c memory arrays objective-c char

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