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

      1. <small id='aFrd4'></small><noframes id='aFrd4'>

        <tfoot id='aFrd4'></tfoot>

        这是什么JS语法?表达式赋值?(x != null &amp;&amp; (y = x))

        时间:2023-10-01
          <tbody id='5Qqeq'></tbody>
      2. <i id='5Qqeq'><tr id='5Qqeq'><dt id='5Qqeq'><q id='5Qqeq'><span id='5Qqeq'><b id='5Qqeq'><form id='5Qqeq'><ins id='5Qqeq'></ins><ul id='5Qqeq'></ul><sub id='5Qqeq'></sub></form><legend id='5Qqeq'></legend><bdo id='5Qqeq'><pre id='5Qqeq'><center id='5Qqeq'></center></pre></bdo></b><th id='5Qqeq'></th></span></q></dt></tr></i><div id='5Qqeq'><tfoot id='5Qqeq'></tfoot><dl id='5Qqeq'><fieldset id='5Qqeq'></fieldset></dl></div>
        <tfoot id='5Qqeq'></tfoot>

            <bdo id='5Qqeq'></bdo><ul id='5Qqeq'></ul>
            • <small id='5Qqeq'></small><noframes id='5Qqeq'>

                • <legend id='5Qqeq'><style id='5Qqeq'><dir id='5Qqeq'><q id='5Qqeq'></q></dir></style></legend>
                • 本文介绍了这是什么JS语法?表达式赋值?(x != null &amp;&amp; (y = x))的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用这个 JS 插件,我遇到了一些我以前从未见过的语法.我明白它在做什么,但我不确定它为什么会起作用.

                  I'm working with this JS plugin, and I've encountered some syntax I've never seen before. I understand what it's doing, but I'm not sure why it works.

                  这是一个例子:

                  settings.maxId != null && (params.max_id = settings.maxId);
                  

                  这只是利用条件和单个 = 吗?这是 JS 常用的语法吗?

                  Is this just taking advantage of conditionals and the single = ? Is this common syntax for JS?

                  推荐答案

                  在 JavaScript 中,= 运算符是一个 表达式 并计算分配的值.因为它是一个表达式,它可以在任何允许使用表达式的地方使用即使它会产生副作用.因此:

                  In JavaScript the = operator is an expression and evaluates the assigned value. Because it is an expression it can be used anywhere an expression is allowed even though it causes a side-effect. Thus:

                  settings.maxId != null && (params.max_id = settings.maxId)
                  

                  意思是:如果 settings.maxId 不为空,那么 (只有这样,因为 && 是 短路) 评估右表达式 (params.max_id = settings.maxId) 进而导致 settings.maxId 的值被分配给 params.max_id.这更清楚写成:

                  Means: If settings.maxId is not null then (and only then, since && is short circuiting) evaluate the right-expression (params.max_id = settings.maxId) which in turn causes the value of settings.maxId to be assigned to params.max_id. This is much more clearly written as:

                  if (settings.maxId != null) {
                    params.max_id = settings.maxId
                  }
                  

                  编码愉快.

                  这篇关于这是什么JS语法?表达式赋值?(x != null &amp;&amp; (y = x))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:是否有包括样式表在内的浏览器条件列表? 下一篇:客户端 Javascript 中的 Base64 编码和解码

                  相关文章

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

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