Shorthand property names
Khi key của object và tên biến giống nhau, có thể sử dụng shorthand property names khi gán giá trị vào object. Đây là tính năng liên quan đến destructuring assignment. Ví dụ sau minh họa gần như toàn bộ.
tstypeWild = {name : string;no : number;genre : string;height : number;weight : number;};constname = "pikachu";constno = 25;constgenre = "mouse pokémon";constheight = 0.4;constweight = 6.0;constpikachu :Wild = {name ,no ,genre ,height ,weight ,};
tstypeWild = {name : string;no : number;genre : string;height : number;weight : number;};constname = "pikachu";constno = 25;constgenre = "mouse pokémon";constheight = 0.4;constweight = 6.0;constpikachu :Wild = {name ,no ,genre ,height ,weight ,};
Đây là dạng rút gọn của cách viết sau.
tsconstpikachu :Wild = {name :name ,no :no ,genre :genre ,height :height ,weight :weight ,};
tsconstpikachu :Wild = {name :name ,no :no ,genre :genre ,height :height ,weight :weight ,};
Tất nhiên cũng có thể viết trên một dòng.
tsconstpikachu :Wild = {name ,no ,genre ,height ,weight };
tsconstpikachu :Wild = {name ,no ,genre ,height ,weight };