首页
导航
博客
电子书
算法
众创
代码
随贴
关于我们
您好,欢迎来到码863代码分享网! 请
[登录]
/
[注册]
搜 索
标题:
*
140
字
TAG标签:
(用空格隔开)
30
字
恢复历史版本:
请选择分类
html
python
javascript
php
sql
c
c++
c#
java
plain
所有人可见
仅自己可见
编辑器:UEditor
编辑器:TinyMCE
编辑器:Editor.md
HTML转MD
HTML转MD2
<p><br/></p><p><br/></p><article class="_2rhmJa"><p>链接:<a href="https://www.jianshu.com/p/8fe1382ba135" _src="https://www.jianshu.com/p/8fe1382ba135">https://www.jianshu.com/p/8fe1382ba135</a></p><p><br/></p><p><br/></p><p>讲解大致会根据下图展开</p><br/><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-c1ff7e988c760ebc.png" data-original-width="1224" data-original-height="1114" data-original-format="image/png" data-original-filesize="314128" data-image-index="0" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-c1ff7e988c760ebc.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp"/></p><blockquote><p>本文部分参考了书籍《你不知道的javascript》上卷</p></blockquote><h5>对象的定义与赋值</h5><p>经常使用的定义与赋值方法<code>obj.prop =value</code>或者<code>obj['prop']=value</code><br/></p><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-4d7533fee7979ef4.png" data-original-width="1004" data-original-height="348" data-original-format="image/png" data-original-filesize="53207" data-image-index="1" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-4d7533fee7979ef4.png?imageMogr2/auto-orient/strip|imageView2/2/w/1004/format/webp"/></p><p><br/></p><h5>Object.defineProperty()语法说明</h5><p><code>Object.defineProperty()</code>的作用就是直接在一个对象上定义一个新属性,或者修改一个已经存在的属性</p><p><button class="VJbwyy" type="button" aria-label="复制代码"><em aria-label="icon: copy" class="anticon anticon-copy"><svg viewbox="64 64 896 896" focusable="false" class="" data-icon="copy" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M832 64H296c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h496v688c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8V96c0-17.7-14.3-32-32-32zM704 192H192c-17.7 0-32 14.3-32 32v530.7c0 8.5 3.4 16.6 9.4 22.6l173.3 173.3c2.2 2.2 4.7 4 7.4 5.5v1.9h4.2c3.5 1.3 7.2 2 11 2H704c17.7 0 32-14.3 32-32V224c0-17.7-14.3-32-32-32zM350 856.2L263.9 770H350v86.2zM664 888H414V746c0-22.1-17.9-40-40-40H232V264h432v624z"></path></svg></em></button></p><pre class="line-numbers language-css">Object.defineProperty(obj, prop, desc)</pre><ol class=" list-paddingleft-2"><li><p>obj 需要定义属性的当前对象</p></li><li><p>prop 当前需要定义的属性名</p></li><li><p>desc 属性描述符</p></li></ol><p>一般通过为对象的属性赋值的情况下,对象的属性可以修改也可以删除,但是通过Object.defineProperty()定义属性,通过描述符的设置可以进行更精准的控制对象属性。</p><h5>属性的特性以及内部属性</h5><p>javacript 有三种类型的属性</p><ol class=" list-paddingleft-2"><li><p>命名数据属性:拥有一个确定的值的属性。这也是最常见的属性</p></li><li><p>命名访问器属性:通过<code>getter</code>和<code>setter</code>进行读取和赋值的属性</p></li><li><p>内部属性:由JavaScript引擎内部使用的属性,不能通过JavaScript代码直接访问到,不过可以通过一些方法间接的读取和设置。比如,每个对象都有一个内部属性<code>[[Prototype]]</code>,你不能直接访问这个属性,但可以通过<code>Object.getPrototypeOf()</code>方法间接的读取到它的值。虽然内部属性通常用一个双吕括号包围的名称来表示,但实际上这并不是它们的名字,它们是一种抽象操作,是不可见的,根本没有上面两种属性有的那种字符串类型的属性</p></li></ol><h5>属性描述符</h5><p>通过Object.defineProperty()为对象定义属性,有两种形式,且不能混合使用,分别为数据描述符,存取描述符,下面分别描述下两者的区别:</p><h6>数据描述符 --特有的两个属性(value,writable)</h6><p><button class="VJbwyy" type="button" aria-label="复制代码"><em aria-label="icon: copy" class="anticon anticon-copy"><svg viewbox="64 64 896 896" focusable="false" class="" data-icon="copy" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M832 64H296c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h496v688c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8V96c0-17.7-14.3-32-32-32zM704 192H192c-17.7 0-32 14.3-32 32v530.7c0 8.5 3.4 16.6 9.4 22.6l173.3 173.3c2.2 2.2 4.7 4 7.4 5.5v1.9h4.2c3.5 1.3 7.2 2 11 2H704c17.7 0 32-14.3 32-32V224c0-17.7-14.3-32-32-32zM350 856.2L263.9 770H350v86.2zM664 888H414V746c0-22.1-17.9-40-40-40H232V264h432v624z"></path></svg></em></button></p><pre class="line-numbers language-csharp">let Person = {}Object.defineProperty(Person, 'name', { value: 'jack', writable: true // 是否可以改变})</pre><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-341b21261bd9366c.png" data-original-width="916" data-original-height="462" data-original-format="image/png" data-original-filesize="77380" data-image-index="2" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-341b21261bd9366c.png?imageMogr2/auto-orient/strip|imageView2/2/w/916/format/webp"/></p><br/><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-69e4dc45d0a6c764.png" data-original-width="876" data-original-height="412" data-original-format="image/png" data-original-filesize="59340" data-image-index="3" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-69e4dc45d0a6c764.png?imageMogr2/auto-orient/strip|imageView2/2/w/876/format/webp"/></p><p>注意,如果描述符中的某些属性被省略,会使用以下默认规则:</p><br/><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-9cd41a36735b667d.png" data-original-width="1870" data-original-height="564" data-original-format="image/png" data-original-filesize="54760" data-image-index="4" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-9cd41a36735b667d.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp"/></p><h6>存取描述符 --是由一对 getter、setter 函数功能来描述的属性</h6><p><code>get</code>:一个给属性提供<code>getter</code>的方法,如果没有<code>getter</code>则为<code>undefined</code>。该方法返回值被用作属性值。默认为<code>undefined</code>。<br/><code>set</code>:一个给属性提供<code>setter</code>的方法,如果没有<code>setter</code>则为<code>undefined</code>。该方法将接受唯一参数,并将该参数的新值分配给该属性。默认值为<code>undefined</code>。</p><p><button class="VJbwyy" type="button" aria-label="复制代码"><em aria-label="icon: copy" class="anticon anticon-copy"><svg viewbox="64 64 896 896" focusable="false" class="" data-icon="copy" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M832 64H296c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h496v688c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8V96c0-17.7-14.3-32-32-32zM704 192H192c-17.7 0-32 14.3-32 32v530.7c0 8.5 3.4 16.6 9.4 22.6l173.3 173.3c2.2 2.2 4.7 4 7.4 5.5v1.9h4.2c3.5 1.3 7.2 2 11 2H704c17.7 0 32-14.3 32-32V224c0-17.7-14.3-32-32-32zM350 856.2L263.9 770H350v86.2zM664 888H414V746c0-22.1-17.9-40-40-40H232V264h432v624z"></path></svg></em></button></p><pre class="line-numbers language-jsx">let Person = {}let temp = nullObject.defineProperty(Person, 'name', { get: function () { return temp }, set: function (val) { temp = val }})</pre><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-96b00b053d6fd42a.png" data-original-width="854" data-original-height="668" data-original-format="image/png" data-original-filesize="81204" data-image-index="5" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-96b00b053d6fd42a.png?imageMogr2/auto-orient/strip|imageView2/2/w/854/format/webp"/></p><h5>数据描述符和存取描述均具有以下描述符</h5><ol class=" list-paddingleft-2"><li><p>configrable 描述属性是否配置,以及可否删除</p></li><li><p>enumerable 描述属性是否会出现在for in 或者 Object.keys()的遍历中</p></li></ol><h6>configrable 代码片段分析</h6><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-885fbf1df3d6a465.png" data-original-width="1358" data-original-height="478" data-original-format="image/png" data-original-filesize="83644" data-image-index="6" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-885fbf1df3d6a465.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp"/></p><p>configurable:false不能删除属性</p><br/><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-65abac28f1baac3b.png" data-original-width="1496" data-original-height="440" data-original-format="image/png" data-original-filesize="78912" data-image-index="7" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-65abac28f1baac3b.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp"/></p><p>configurable:false不能重新定义属性</p><br/><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-6cfce802f175016b.png" data-original-width="942" data-original-height="598" data-original-format="image/png" data-original-filesize="109059" data-image-index="8" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-6cfce802f175016b.png?imageMogr2/auto-orient/strip|imageView2/2/w/942/format/webp"/></p><p>等价上一张图的代码</p><br/><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-a89db7cd533efbcc.png" data-original-width="882" data-original-height="596" data-original-format="image/png" data-original-filesize="107788" data-image-index="9" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-a89db7cd533efbcc.png?imageMogr2/auto-orient/strip|imageView2/2/w/882/format/webp"/></p><p>与上一张图的代码进行对比</p><br/><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-fecfb1b9d9d4eee8.png" data-original-width="1150" data-original-height="534" data-original-format="image/png" data-original-filesize="83545" data-image-index="10" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-fecfb1b9d9d4eee8.png?imageMogr2/auto-orient/strip|imageView2/2/w/1150/format/webp"/></p><p>configurable:true能删除属性</p><br/><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-210b70d4146f46ec.png" data-original-width="1022" data-original-height="736" data-original-format="image/png" data-original-filesize="158029" data-image-index="11" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-210b70d4146f46ec.png?imageMogr2/auto-orient/strip|imageView2/2/w/1022/format/webp"/></p><p>configurable:true能够定义属性</p><br/><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-dadc376bbc6c23b1.png" data-original-width="1086" data-original-height="736" data-original-format="image/png" data-original-filesize="155209" data-image-index="12" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-dadc376bbc6c23b1.png?imageMogr2/auto-orient/strip|imageView2/2/w/1086/format/webp"/></p><p>configurable:false与上图做对照</p><p>从以上代码运行结果分析总结可知:</p><blockquote><ol class=" list-paddingleft-2"><li><p>configurable: false 时,不能删除当前属性,且不能重新配置当前属性的描述符(有一个小小的意外:可以把writable的状态由true改为false,但是无法由false改为true),但是在writable: true的情况下,可以改变value的值</p></li><li><p>configurable: true时,可以删除当前属性,可以配置当前属性所有描述符。</p></li></ol></blockquote><h6>enumerable 代码片段分析</h6><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-25ab11c6f042ed86.png" data-original-width="1240" data-original-height="1072" data-original-format="image/png" data-original-filesize="202697" data-image-index="13" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-25ab11c6f042ed86.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp"/></p><br/><p>注意:以下二种区别</p><br/><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-d700d59cf2c6251b.png" data-original-width="898" data-original-height="548" data-original-format="image/png" data-original-filesize="68332" data-image-index="14" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-d700d59cf2c6251b.png?imageMogr2/auto-orient/strip|imageView2/2/w/898/format/webp"/></p><br/><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-ed831b5f32e5cac2.png" data-original-width="882" data-original-height="532" data-original-format="image/png" data-original-filesize="75948" data-image-index="15" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-ed831b5f32e5cac2.png?imageMogr2/auto-orient/strip|imageView2/2/w/882/format/webp"/></p><h5>不变性</h5><ol class=" list-paddingleft-2"><li><p>对象常量<br/>结合writable: false 和 configurable: false 就可以创建一个真正的常量属性(不可修改,不可重新定义或者删除)</p></li></ol><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-53ceb8f0c574556c.png" data-original-width="1486" data-original-height="828" data-original-format="image/png" data-original-filesize="182335" data-image-index="16" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-53ceb8f0c574556c.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp"/></p><p>对象常量</p><ol start="2" class=" list-paddingleft-2"><li><p>禁止扩展<br/>如果你想禁止一个对象添加新属性并且保留已有属性,就可以使用Object.preventExtensions(...)</p></li></ol><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-e04c673d73514ae1.png" data-original-width="1572" data-original-height="370" data-original-format="image/png" data-original-filesize="72737" data-image-index="17" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-e04c673d73514ae1.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp"/></p><p>禁止扩展片段1</p><br/><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-bd0d1ef4b505d0bb.png" data-original-width="1058" data-original-height="778" data-original-format="image/png" data-original-filesize="143906" data-image-index="18" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-bd0d1ef4b505d0bb.png?imageMogr2/auto-orient/strip|imageView2/2/w/1058/format/webp"/></p><p>禁止扩展片段2</p><p>在非严格模式下,创建属性gender会静默失败,在严格模式下,将会抛出异常。</p><ol start="3" class=" list-paddingleft-2"><li><p>密封<br/>Object.seal()会创建一个密封的对象,这个方法实际上会在一个现有对象上调用object.preventExtensions(...)并把所有现有属性标记为configurable:false。</p></li></ol><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-446c94b28768fbe9.png" data-original-width="1498" data-original-height="750" data-original-format="image/png" data-original-filesize="143359" data-image-index="19" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-446c94b28768fbe9.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp"/></p><p>密封</p><br/><p>所以, 密封之后不仅不能添加新属性,也不能重新配置或者删除任何现有属性(虽然可以改属性的值)</p><ol start="4" class=" list-paddingleft-2"><li><p>冻结<br/>Object.freeze()会创建一个冻结对象,这个方法实际上会在一个现有对象上调用Object.seal(),并把所有现有属性标记为writable: false,这样就无法修改它们的值。</p><p><br/></p><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-1f6ad10fa20995ae.png" data-original-width="1472" data-original-height="878" data-original-format="image/png" data-original-filesize="178903" data-image-index="20" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-1f6ad10fa20995ae.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp"/></p><p>冻结</p></li></ol><p>这个方法是你可以应用在对象上级别最高的不可变性,它会禁止对于对象本身及其任意直接属性的修改(但是这个对象引用的其他对象是不受影响的)<br/>你可以深度冻结一个对象,具体方法为,首先这个对象上调用Object.freeze()然后遍历它引用的所有对象,并在这些对象上调用Object.freeze()。但是一定要小心,因为这么做有可能会无意中冻结其他共享对象。</p><h5>属性定义和属性赋值</h5><p>最后一小节,总结一下上述内容</p><h6>属性定义,通过Object.defineProperty()形式</h6><ol class=" list-paddingleft-2"><li><p>如果Obj没有名为Prop的自身属性的话:如果Obj是可扩展的话,则创建Prop这个自身属性,否则拒绝</p></li><li><p>如果Obj已经有了名为Prop的自身属性:则按照下面的步骤重新配置这个属性</p></li><li><p>如果这个已有的属性是不可配置的,则进行下面的操作会被拒绝</p></li></ol><p><button class="VJbwyy" type="button" aria-label="复制代码"><em aria-label="icon: copy" class="anticon anticon-copy"><svg viewbox="64 64 896 896" focusable="false" class="" data-icon="copy" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M832 64H296c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h496v688c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8V96c0-17.7-14.3-32-32-32zM704 192H192c-17.7 0-32 14.3-32 32v530.7c0 8.5 3.4 16.6 9.4 22.6l173.3 173.3c2.2 2.2 4.7 4 7.4 5.5v1.9h4.2c3.5 1.3 7.2 2 11 2H704c17.7 0 32-14.3 32-32V224c0-17.7-14.3-32-32-32zM350 856.2L263.9 770H350v86.2zM664 888H414V746c0-22.1-17.9-40-40-40H232V264h432v624z"></path></svg></em></button></p><pre class="line-numbers language-jsx">1: 将一个数据属性转换成访问器属性,反之变然2: 改变`[[Configurable]]`或`[[Enumerable]]`3: 改变[[Writable]]由false变为true4: 在`[[Writable]]`为`false`时改变`[[Value]]`5: 改变[[Get]]或[[Set]]</pre><ol start="4" class=" list-paddingleft-2"><li><p>否则这个已有的属性可以被重新配置</p></li></ol><h6>属性赋值,通过obj.prop = ''prop"形式</h6><ol class=" list-paddingleft-2"><li><p>如果在原型链上存在一个名为<code>P</code>的只读属性(只读的数据属性或者没有<code>setter</code>的访问器属性),则拒绝</p></li><li><p>如果在原型链上存在一个名为<code>P</code>的且拥有<code>setter</code>的访问器属性,则调用这个<code>setter</code></p></li><li><p>如果没有名为<code>P</code>的自身属性,则如果这个对象是可扩展的,就创建一个新属性,否则,如果这个对象是不可扩展的,则拒绝</p></li><li><p>如果已经存在一个可写的名为P的自身属性,则调用Object.defineProperty(),该操作只会更改<code>P</code>属性的值,其他的特性(比如可枚举性)都不会改变</p></li></ol><h5>作用以及影响</h5><p>属性的定义操作和赋值操作各自有自己的作用和影响。<br/><strong>赋值可能会调用原型上的<code>setter</code>,定义会创建一个自身属性</strong>。<br/><strong>原型链中的同名只读属性可能会阻止赋值操作,但不会阻止定义操作</strong>。如果原型链中存在一个同名的只读属性,则无法通过赋值的方式在原对象上添加这个自身属性,必须使用定义操作才可以。这项限制是在ECMAScript 5.1中引入的<br/></p><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-f978709d73c32b5d.png" data-original-width="1640" data-original-height="540" data-original-format="image/png" data-original-filesize="89047" data-image-index="21" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-f978709d73c32b5d.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp"/></p><p><br/></p><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-d6e8aa6461813e68.png" data-original-width="944" data-original-height="798" data-original-format="image/png" data-original-filesize="130889" data-image-index="22" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-d6e8aa6461813e68.png?imageMogr2/auto-orient/strip|imageView2/2/w/944/format/webp"/></p><p><br/></p><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-f42ff3eac0792f2a.png" data-original-width="1724" data-original-height="806" data-original-format="image/png" data-original-filesize="135988" data-image-index="23" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-f42ff3eac0792f2a.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp"/></p><br/><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-3561b2bb74a80778.png" data-original-width="1432" data-original-height="1054" data-original-format="image/png" data-original-filesize="190982" data-image-index="24" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-3561b2bb74a80778.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp"/></p><br/>赋值运算符不会改变原型链上的属性<br/>不能通过为<code>obj.foo</code>赋值来改变<code>proto.foo</code>的值。这种操作只会在<code>obj</code>上新建一个自身属性<br/><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-ba6affa8f78c4a89.png" data-original-width="1040" data-original-height="528" data-original-format="image/png" data-original-filesize="83234" data-image-index="25" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-ba6affa8f78c4a89.png?imageMogr2/auto-orient/strip|imageView2/2/w/1040/format/webp"/></p><br/>对象字面量中的属性是通过定义操作添加的。<br/><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-d91e7e26decfa23b.png" data-original-width="802" data-original-height="706" data-original-format="image/png" data-original-filesize="72155" data-image-index="26" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-d91e7e26decfa23b.png?imageMogr2/auto-orient/strip|imageView2/2/w/802/format/webp"/></p><p><br/></p><p>再次啰嗦一次,记住以下两种形式的区别:</p><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-16ef54cf96c184da.png" data-original-width="1466" data-original-height="116" data-original-format="image/png" data-original-filesize="13651" data-image-index="27" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-16ef54cf96c184da.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp"/></p><p>上面的代码等同于:</p><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-b4633515fd327cec.png" data-original-width="1410" data-original-height="374" data-original-format="image/png" data-original-filesize="53414" data-image-index="28" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-b4633515fd327cec.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp"/></p><p>另一方面:</p><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-8a2a3b2da50e0868.png" data-original-width="1420" data-original-height="176" data-original-format="image/png" data-original-filesize="24810" data-image-index="29" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-8a2a3b2da50e0868.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp"/></p><p>上面的代码等同于:</p><p><img data-original-src="https://upload-images.jianshu.io/upload_images/5016475-f5fa67373fc34d36.png" data-original-width="1446" data-original-height="334" data-original-format="image/png" data-original-filesize="52001" data-image-index="30" style="cursor: zoom-in;" class="" src="https://upload-images.jianshu.io/upload_images/5016475-f5fa67373fc34d36.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp"/></p></article><p><br/></p><p><br/></p><p><em aria-label="ic-like" class="anticon"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-like"></use></svg></em></p><p><span class="_1LOh_5" role="button" tabindex="-1" aria-label="查看点赞列表">131人点赞<em aria-label="icon: right" class="anticon anticon-right"><svg viewbox="64 64 896 896" focusable="false" class="" data-icon="right" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M765.7 486.8L314.9 134.7A7.97 7.97 0 0 0 302 141v77.3c0 4.9 2.3 9.6 6.1 12.6l360 281.1-360 281.1c-3.9 3-6.1 7.7-6.1 12.6V883c0 6.7 7.7 10.4 12.9 6.3l450.8-352.1a31.96 31.96 0 0 0 0-50.4z"></path></svg></em></span></p><p><em aria-label="ic-dislike" class="anticon"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-dislike"></use></svg></em></p><p><a class="_3BUZPB _1x1ok9 _1OhGeD" href="/nb/22236264" target="_blank" rel="noopener noreferrer"><em aria-label="ic-notebook" class="anticon"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-notebook"></use></svg></em>javascript基础</a></p><p><em aria-label="ic-others" class="anticon"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><use xlink:href="#ic-others"></use></svg></em></p><p><br/><br/><br/><br/><br/></p><p><br/></p>
CopyRight 2002~2023 精通2100网 联系邮箱:qqtxt@163.com
版权所有:精通2100网
湘ICP备2023018646号-1
MYSQl共执行 4 个查询,用时 0.0032598972320557 秒,PHP脚本用时 0.005793 秒,占用内存 0.694 MB,Gzip 已启用