• <tfoot id='gBf3i'></tfoot>
    <legend id='gBf3i'><style id='gBf3i'><dir id='gBf3i'><q id='gBf3i'></q></dir></style></legend>
  • <small id='gBf3i'></small><noframes id='gBf3i'>

    <i id='gBf3i'><tr id='gBf3i'><dt id='gBf3i'><q id='gBf3i'><span id='gBf3i'><b id='gBf3i'><form id='gBf3i'><ins id='gBf3i'></ins><ul id='gBf3i'></ul><sub id='gBf3i'></sub></form><legend id='gBf3i'></legend><bdo id='gBf3i'><pre id='gBf3i'><center id='gBf3i'></center></pre></bdo></b><th id='gBf3i'></th></span></q></dt></tr></i><div id='gBf3i'><tfoot id='gBf3i'></tfoot><dl id='gBf3i'><fieldset id='gBf3i'></fieldset></dl></div>

        <bdo id='gBf3i'></bdo><ul id='gBf3i'></ul>

      1. 布尔对象的意义何在?

        What#39;s the point of the Boolean object?(布尔对象的意义何在?)

        <small id='K8fIk'></small><noframes id='K8fIk'>

        <legend id='K8fIk'><style id='K8fIk'><dir id='K8fIk'><q id='K8fIk'></q></dir></style></legend>
        <i id='K8fIk'><tr id='K8fIk'><dt id='K8fIk'><q id='K8fIk'><span id='K8fIk'><b id='K8fIk'><form id='K8fIk'><ins id='K8fIk'></ins><ul id='K8fIk'></ul><sub id='K8fIk'></sub></form><legend id='K8fIk'></legend><bdo id='K8fIk'><pre id='K8fIk'><center id='K8fIk'></center></pre></bdo></b><th id='K8fIk'></th></span></q></dt></tr></i><div id='K8fIk'><tfoot id='K8fIk'></tfoot><dl id='K8fIk'><fieldset id='K8fIk'></fieldset></dl></div>
            <bdo id='K8fIk'></bdo><ul id='K8fIk'></ul>
              <tbody id='K8fIk'></tbody>

              1. <tfoot id='K8fIk'></tfoot>

                • 本文介绍了布尔对象的意义何在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在阅读关于 JavaScript 的 Mozilla 手册,我在阅读中来到了这一点,布尔对象.我看不到它们的单一用途.他们的意义何在?为什么不只使用 truefalse?

                  I am reading through the Mozilla Manual on JavaScript, and I come to this point in my reading, Boolean object. I can't see a single use for them. What's their point? Why wouldn't you use just true and false?

                  顺便说一句,我根本不懂 Java,而且我不害怕学习新事物,这也是我尝试学习 JavaScript 的原因.我是一名 PHP 程序员,一名后端人员,我想学习如何做一些前端工作,所以我正在阅读 Mozilla JavaScript 指南.

                  By the way, I don't know Java at all and I'm not afraid of learning new things that consequently why I'm trying to learn JavaScript. I'm a PHP programmer, a back end guy, and I'd like to learn how to do some front end work, so I'm reading the Mozilla JavaScript Guide.

                  推荐答案

                  因为这是(有点遗憾)语言的定义方式——我怀疑它最初是为了性能/优化;请注意下面分配给 string 属性的情况.(Java 的工作方式类似,尽管 Scala 和 Python 在很大程度上拒绝这种区别).

                  Because this is (somewhat sadly) how the language was defined -- I suspect it was originally for performance/optimization; note the case of assignment to a string property below. (Java works similarly, although Scala and Python largely reject this distinction).

                  请注意,Boolean 并不是唯一的包装器类型".例如,还有 StringNumber.

                  Note that Boolean isn't the only "wrapper type". There are also String and Number, for instance.

                  因此,仍然存在许多怪癖(以下可能同样适用于布尔值):

                  Because of this there remains a number of quirks (the below could just as much apply to Boolean):

                  typeof("foo") // string
                  typeof(new String("foo")) // object
                  "foo" instanceof String // false
                  new String("foo") instanceof String // true
                  
                  // result is undefined: a string is a primitive and silently "ate" the assignment
                  // this also makes it a much cheaper value as it's not a "real" object
                  x = "f"; x.bar = 42; x.bar
                  
                  // result is 42: a String is a "real" object with real properties!
                  // however, this also means that it may have a good bit more overhead
                  x = new String("f"); x.bar = 42; x.bar
                  

                  我知道这并没有回答"这个问题,而是在火上扔了一些木头;-)

                  I know this didn't "answer" the question, but rather chucks some more wood on the fire ;-)

                  上述唯一真正的陷阱"可能是 new Boolean(false) 是一个真值.

                  The only real "gotcha" otherwise from the above is that perhaps new Boolean(false) is a truth-y value.

                  编码愉快.

                  这篇关于布尔对象的意义何在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pause youtube video, youtube api(暂停 youtube 视频,youtube api)
                  Youtube iframe api not triggering onYouTubeIframeAPIReady(Youtube iframe api 未触发 onYouTubeIframeAPIReady)
                  How can I stop a video with Javascript in Youtube?(如何在 Youtube 中停止使用 Javascript 的视频?)
                  How to call Greasemonkey#39;s GM_ functions from code that must run in the target page scope?(如何从必须在目标页面范围内运行的代码中调用 Greasemonkey 的 GM_ 函数?)
                  How do you mute an embedded Youtube player?(如何使嵌入式 Youtube 播放器静音?)
                  How to get number of video views with YouTube API?(如何使用 YouTube API 获取视频观看次数?)

                      • <bdo id='2eDae'></bdo><ul id='2eDae'></ul>

                          <small id='2eDae'></small><noframes id='2eDae'>

                        1. <tfoot id='2eDae'></tfoot>
                        2. <legend id='2eDae'><style id='2eDae'><dir id='2eDae'><q id='2eDae'></q></dir></style></legend>
                          <i id='2eDae'><tr id='2eDae'><dt id='2eDae'><q id='2eDae'><span id='2eDae'><b id='2eDae'><form id='2eDae'><ins id='2eDae'></ins><ul id='2eDae'></ul><sub id='2eDae'></sub></form><legend id='2eDae'></legend><bdo id='2eDae'><pre id='2eDae'><center id='2eDae'></center></pre></bdo></b><th id='2eDae'></th></span></q></dt></tr></i><div id='2eDae'><tfoot id='2eDae'></tfoot><dl id='2eDae'><fieldset id='2eDae'></fieldset></dl></div>
                            <tbody id='2eDae'></tbody>