Self-references in object literals/initializers
P粉921130067
P粉921130067 2023-08-29 12:38:19
0
2
345
<p>Is there any way to make something like the following work in JavaScript? </p> <pre class="brush:php;toolbar:false;">var foo = { a: 5, b: 6, c: this.a this.b // Doesn't work };</pre> <p>In its current form, this code obviously throws a reference error because <code>this</code> does not reference <code>foo</code>. But<em>yes</em>Is there any way to make the value in an object literal property dependent on other previously declared properties? </p>
P粉921130067
P粉921130067

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!