适配器方法 :
功能 : 将预先加载的对象属性对应转换到新对象上
<code class="hljs avrasm has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"> adapter: function(ob){ var newOb = { name : ob<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.name</span>, pic : ob<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.pic</span>, life : ob<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.blood</span> || ob<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.life</span>, life_grow : ob<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.blood</span>_grow_up, maxlife: ob<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.lifeMax</span>, att : ob<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.attack</span>, attack_grow : ob<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.attack</span>_grow_up, minatt : ob<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.fightMin</span>, maxatt : ob<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.fightMax</span>, level : ob<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.level</span>, } return newOb },</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li></ul><div class="save_code tracking-ad" data-mod="popu_249" style="box-sizing: border-box; position: absolute; height: 60px; right: 30px; top: 5px; color: rgb(255, 255, 255); cursor: pointer; z-index: 2;"> </div>
例子 :
<code class="hljs avrasm has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">ob = { name : <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"小明"</span>, age : <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">15</span>, money : <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1000</span>, } <span class="hljs-label" style="box-sizing: border-box;">adapter:</span> function(ob){ var newOb = { mingzi : ob<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.name</span>, suishu : ob<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.age</span>, qian : ob<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.money</span>, } return newOb }, var ob1 = this<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.adapter</span>(ob) cc<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.log</span>(ob1<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.mingzi</span>) //<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"小明"</span> cc<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.log</span>(ob1<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.suishu</span>) //<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">15</span> cc<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.log</span>(ob1<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.qian</span>) //<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1000</span> </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li></ul>