- ES6 Enhanced object literal syntax can take an external object like salary object and make it a property of the developer object as shown below: const salary = { fixed: '$200k', variable: '$100k' } const developer = { // salary: salary // Before ES6 salary // ES6 way } developer; // { salary: { fixed: '$200k', variable: '$100k' } } - If any change is made in salary object, same change needs to be made inside the developer object for salary object which is present as property of developer object.
const salary = { fixed: '$200k', variable: '$50k' } const developer = { salary, /* Before ES6 greet: function(name){ console.log(`Salary credited. Enjoy ${name}!`); }*/ // ES6 Way greet(name){ console.log(`Salary credited. Enjoy ${name}!`); } } developer.greet("Peter");
const seasons = ['winter','summer','spring', 'monsoon','autumn']; const fruits = { [seasons[0]]: 'apple', [seasons[1]]: 'mango', [[seasons.length]]: 'cherry' } fruits; // { '5': 'cherry', winter: 'apple', summer: 'mango' }
免責事項: 提供されるすべてのリソースの一部はインターネットからのものです。お客様の著作権またはその他の権利および利益の侵害がある場合は、詳細な理由を説明し、著作権または権利および利益の証拠を提出して、電子メール [email protected] に送信してください。 できるだけ早く対応させていただきます。
Copyright© 2022 湘ICP备2022001581号-3