javascript名称空间被污染了吗? [英] Is javascript namespace polluted?

查看:100
本文介绍了javascript名称空间被污染了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对js名称空间没有很好的把握,而且WAGing *是标题,但这是我对正在发生的事情的猜测之一。

I do not have a good grasp of the js namespace and am WAGing* re the title, but that's one of my guesses about what's happening.


  • WAG = Wild Guess

我的应用程序崩溃(显着);试图找出原因。事实上,在3对Q / A对之后,它会炸毁整个Chrome标签..! 我开始怀疑我的代码中出错了...

My app is crashing (dramatically); trying to figure out why. In fact, after 3 Q/A pairs, it blows up the entire Chrome tab..! I'm beginning to suspect I've done something wrong in my code...

警告:保存您的浏览会话运行这些jsFiddles。 (在Chrome中,jsFiddle只会炸毁自己的标签,但我无法对其他浏览器发表评论)

jsFiddle One


jsFiddle Two - 欺骗以防jsFiddle One被吹走

请帮助我准确理解我今天所犯的那种壮观的愚蠢行为。

Please help me to understand exactly which spectacular moronism I've committed today.

HTML:

<div id="result">
    <div class="truth tr0"><h2>---</h2></div>
    <div class="truth tr1"><h2>answer to one</h2></div>
    <div class="truth tr2"><h2>answer to two</h2></div>
    <div class="truth tr3"><h2>answer to three</h2></div>
    <div class="truth tr4"><h2>answer to four</h2></div>
 </div>   
<div id="replaceLink">
    <div class="youcould yc1">
        <a href="#2"><h2>QUESTION ONE</h2></a>
    </div>
    <div class="youcould yc2">
        <a href="#3"><h2>QUESTION TWO</h2></a>
    </div>
    <div class="youcould yc3">
        <a href="#4"><h2>QUESTION THREE</h2></a>
    </div>
    <div class="youcould yc4">
        <a href="#5"><h2>QUESTION FOUR</h2></a>
    </div>
    <div class="youcould yc5">
        <a href="#6"><h2>THANK YOU</h2></a>
    </div>
</div>

<div id="response"></div>
<input type="button" id="mybutt" value="Start Test" />

Javascript / jQuery:

var cnt = 0;
var window = {};
window.arrDone = [];

function nextQues() {
    if (window.arrDone.length == 4) return 5;

    success = 0;
    while (success == 0) {
        nn = Math.floor(Math.random() * 3) + 1;
        if (window.arrDone.indexOf(nn) == -1 && nn != 5) {
            success++;
            window.arrDone.push(nn);
        }
    }
    return nn;
}

$('.youcould, .truth').hide();
$('.tr0').show();

$('.youcould').click(function() {
    $(this).hide();
    thisA = window.arrDone[window.arrDone.length -1];
    $('.tr'+thisA).show();
});

$('.truth').click(function() {
    $(this).hide();
    nextQ = nextQues();
    $('.yc'+nextQ).show();
});

$('#mybutt').click(function () {
    $(this).hide();
    $('.tr0').hide();
    nextQ = nextQues();
    $('.yc'+nextQ).show();
});


推荐答案

你的while循环在第三遍无限运行,因为它不符合条件。

Your while loop runs infinitely on the third pass because it doesn't meet the condition.

这篇关于javascript名称空间被污染了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆