• <bdo id='bpWPV'></bdo><ul id='bpWPV'></ul>
      <legend id='bpWPV'><style id='bpWPV'><dir id='bpWPV'><q id='bpWPV'></q></dir></style></legend><tfoot id='bpWPV'></tfoot>

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

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

        可以使用解构赋值来影响 CoffeeScript 中的投影吗?

        Can destructuring assignment be used to effect a projection in CoffeeScript?(可以使用解构赋值来影响 CoffeeScript 中的投影吗?)
      2. <tfoot id='svbqh'></tfoot>

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

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

                <tbody id='svbqh'></tbody>

                • <legend id='svbqh'><style id='svbqh'><dir id='svbqh'><q id='svbqh'></q></dir></style></legend>
                • <i id='svbqh'><tr id='svbqh'><dt id='svbqh'><q id='svbqh'><span id='svbqh'><b id='svbqh'><form id='svbqh'><ins id='svbqh'></ins><ul id='svbqh'></ul><sub id='svbqh'></sub></form><legend id='svbqh'></legend><bdo id='svbqh'><pre id='svbqh'><center id='svbqh'></center></pre></bdo></b><th id='svbqh'></th></span></q></dt></tr></i><div id='svbqh'><tfoot id='svbqh'></tfoot><dl id='svbqh'><fieldset id='svbqh'></fieldset></dl></div>
                  本文介绍了可以使用解构赋值来影响 CoffeeScript 中的投影吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在理解 CoffeeScript 中的解构赋值时遇到了一些麻烦.documentation 包含几个示例,它们似乎暗示在分配期间重命名对象可以用于投影(即映射、翻译、变换)源对象.

                  I'm having some trouble understanding destructuring assignment in CoffeeScript. The documentation contains a couple of examples which together seem to imply that renaming objects during assignment can be used to project (i.e. map, translate, transform) a source object.

                  我正在尝试将 a = [ { Id: 1, Name: 'Foo' }, { Id: 2, Name: 'Bar' } ] 投影到 b = [ {x: 1 }, { x: 2 } ].我尝试了以下但没有成功;我显然误解了一些东西.谁能解释这是否可能?

                  I am trying to project a = [ { Id: 1, Name: 'Foo' }, { Id: 2, Name: 'Bar' } ] into b = [ { x: 1 }, { x: 2 } ]. I've tried the following without success; I've clearly misunderstood something. Can anyone explain whether this is possible?

                  a = [ { Id: 1, Name: 'Foo' }, { Id: 2, Name: 'Bar' } ]
                  
                  # Huh? This returns 1.
                  x = [ { Id } ] = a
                  
                  # Boo! This returns [ { Id: 1, Name: 'Foo' }, { Id: 2, Name: 'Bar' } ] 
                  y = [ { x: Id } ] = a
                  
                  # Boo! This returns [ { Id: 1, Name: 'Foo' }, { Id: 2, Name: 'Bar' } ]
                  z = [ { Id: x } ] = a
                  

                  CoffeeScript 的并行赋值示例

                  theBait   = 1000
                  theSwitch = 0
                  
                  [theBait, theSwitch] = [theSwitch, theBait]
                  

                  我将这个例子理解为暗示可以重命名变量,在这种情况下用于执行交换.

                  I understand this example as implying that variables can be renamed which in this case is used to perform a swap.

                  futurists =
                    sculptor: "Umberto Boccioni"
                    painter:  "Vladimir Burliuk"
                    poet:
                      name:   "F.T. Marinetti"
                      address: [
                        "Via Roma 42R"
                        "Bellagio, Italy 22021"
                      ]
                  
                  {poet: {name, address: [street, city]}} = futurists
                  

                  我将这个示例理解为从任意对象定义属性的选择,其中包括将数组的元素分配给变量.

                  I understand this example as defining a selection of properties from an arbitrary object which includes assigning the elements of an array to variables.

                  a = [ 
                    { Id: 0, Name: { First: 'George', Last: 'Clinton' } },
                    { Id: 1, Name: { First: 'Bill', Last: 'Bush' } },
                  ]
                  
                  # The old way I was doing it.
                  old_way = _.map a, x ->
                      { Id: id, Name: { First: first, Last: last } } = x
                      { id, first, last }
                  
                  # Using thejh's solution...
                  new_way = ({id, first, last} for {Id: id, Name: {First: first, Last: last}} in a)
                  
                  console.log new_way
                  

                  推荐答案

                  b = ({x} for {Id: x} in a) 有效:

                  coffee> a = [ { Id: 1, Name: 'Foo' }, { Id: 2, Name: 'Bar' } ]
                  [ { Id: 1, Name: 'Foo' },
                    { Id: 2, Name: 'Bar' } ]
                  coffee> b = ({x} for {Id: x} in a)
                  [ { x: 1 }, { x: 2 } ]
                  coffee>
                  

                  这篇关于可以使用解构赋值来影响 CoffeeScript 中的投影吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                  Rails 3.1 ajax:success handling(Rails 3.1 ajax:成功处理)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                  getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)

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

                  <legend id='wo2DA'><style id='wo2DA'><dir id='wo2DA'><q id='wo2DA'></q></dir></style></legend>
                • <tfoot id='wo2DA'></tfoot>

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