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

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

        <legend id='So1DS'><style id='So1DS'><dir id='So1DS'><q id='So1DS'></q></dir></style></legend>

        <tfoot id='So1DS'></tfoot>

      1. OO Javascript 是否有 `to_bool` 或 `__len__` 等价物?

        时间:2023-09-04
        • <small id='ZWDhA'></small><noframes id='ZWDhA'>

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

                • <bdo id='ZWDhA'></bdo><ul id='ZWDhA'></ul>

                  <legend id='ZWDhA'><style id='ZWDhA'><dir id='ZWDhA'><q id='ZWDhA'></q></dir></style></legend>

                  本文介绍了OO Javascript 是否有 `to_bool` 或 `__len__` 等价物?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  OO JS 是否有将实例对象转换为布尔值的机制?我希望能够在条件句中直接使用自定义实例对象,并按照 !!(new Foo(0)) === false, !!(newFoo(1)) === true.

                  Does OO JS have a mechanism for casting instance objects to boolean? I would like to be able to use custom instance objects directly in conditionals, and make assertions along the lines of !!(new Foo(0)) === false, !!(new Foo(1)) === true.

                  • Python 有 __nonzero____len__(参见 这里)

                  Ruby 有 to_bool.

                  JS如何对字符串字面量""和零0做到这一点?

                  How does JS do this for String literals "" and zero 0?

                  推荐答案

                  不,JS 没有提供强制转换为布尔值的陷阱方法.值的真实性静态确定由语言规则和无法更改.

                  No, JS does not provide a trap method for casting to boolean. Truthiness of a value is statically determined by the language rules and cannot be changed.

                  您应该为您的实例提供一个可以显式调用的方法,例如 isValid()isTruthy()isEmpty() 或任何概念你的对象代表.

                  You should give your instances a method to be explicitly invoked like isValid(), isTruthy(), isEmpty() or whatever concept your object represents.

                  这篇关于OO Javascript 是否有 `to_bool` 或 `__len__` 等价物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:JavaScript IF 语句 boolean strict 下一篇:JS 生成随机布尔值

                  相关文章

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

                  1. <legend id='qukiJ'><style id='qukiJ'><dir id='qukiJ'><q id='qukiJ'></q></dir></style></legend>

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

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

                    2. <tfoot id='qukiJ'></tfoot>