首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >执行"...used超出作用域“。KSLint中的错误是否导致'[1]为null或不是对象‘错误?

执行"...used超出作用域“。KSLint中的错误是否导致'[1]为null或不是对象‘错误?
EN

Stack Overflow用户
提问于 2012-09-14 21:31:44
回答 1查看 166关注 0票数 1

我尝试使用JavaScript填充下拉列表,但在IE8中遇到以下错误:

消息:'1‘为null或不是对象行: 59字符:3代码:0

当我通过调试器(在本例中为JSBin)推送代码时,我在代码中看到以下错误:

第59行: var视图= $(‘#ai1ec- $selected_view -’+ matches1 );- 'matches‘超出范围使用。

JSBin中的这个错误会与IE8中的错误相关吗?当代码在Chrome、FF或IE9上运行时,任何错误都不会填充。

下面是有问题的代码片段。

代码语言:javascript
复制
// Make current view actively selected in view dropdown button.
    var classes = $('body').attr( 'class' ).split( ' ' );
    for ( i in classes ) {
        // Extract current view from the body class.
        var matches = /ai1ec-action-([\w]+)/.exec( classes[i] );
        if ( matches != null ) break;
    }
    // Get the dropdown menu link of the active view.
    var $selected_view = $( '#ai1ec-view-' + matches[1] );
    // Replace contents of dropdown button with menu link, plus the caret.
    $( '#ai1ec-current-view' )
        .contents()
            .remove()
            .end()
        .prepend( $selected_view.contents().clone() )
        .append( '<span class="caret"></span>' );
    // Deactivate all dropdown menu items.
    $( '#ai1ec-view-dropdown .dropdown-menu li' ).removeClass( 'active' );
    // Activate only currently selected dropdown menu item.
    $selected_view.parent().addClass( 'active' );
EN

回答 1

Stack Overflow用户

发布于 2012-09-14 21:43:05

不是的。超出范围的linter提示/错误/消息可能是因为变量是在for- in -loop的主体块中声明的;这应该可以工作。

然而,matches似乎是导致异常的null。只要matches不为null,您就会中断循环,但这并不能保证某些东西确实匹配-循环可能刚刚结束,而matches仍然为null。

顺便说一句:你不应该使用for-in-循环来枚举split返回的数组的属性,你想用一个普通的for-循环来迭代这些项。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12425633

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档