标签:sea function boolean 对象 oid hello ror default rest
let input = [1, 2];
let [first, second] = input;
console.log(first,second);
[first, second] = [second, first];
function f([first, second]: [number, number]){
console.log(first,second);
}
f([1,2]);
let [first, ...rest] = [1,2,3,4];
console.log(first,rest);
let [first] = [1,2,3,4];
console.log(first);
let [, second, , fourth] = [1,2,3,4];
console.log(second,fourth);
let tuple: [number, string, boolean] = [7, "hello", true];
let [a, b, c] = tuple;
let [a, ...bc] = tuple;
let [a,b,c, ...d] = tuple;
let [a] = tuple;
let [, b] = tuple;
let o = {
a: "foo",
b: 12,
c: "bar"
}
let {a, b} = o;
({a, b} = {a:"baz",b:101});
let {a, ...passthrough} = o;
let total = passthrough.b + passthrough.c.length;
let {a:newName1, b:newName2} = o;
let {a, b}: {a:string, b:number} = o;
function keepWholeObject(wholeObject: {a:string, b?:number}){
let {a,b = 1001} = wholeObject;
}
type C = {a:string, b?: number}
function f({a,b}: C): void{
}
function f({ a="", b = 0} = {} ): void{
}
f();
function f({a,b = 0 } = {a: "" }): void {
}
let first = [1, 2];
let second = [3, 4];
let bothPlus = [0, ...first, ...second, 5];
let defaults = {food: "spicy" ,price : "$$" , ambiance: "noisy" };
let search = {...defaults, food: "rich" };
class C {
p = 12;
m() {
}
}
let c = new C();
let clone = {...c};
clone.p;
clone.m(); // error!
标签:sea function boolean 对象 oid hello ror default rest
原文地址:https://www.cnblogs.com/baiqian/p/12080323.html