速写属性
var name = "徐华";
var age = 18;
var person = {
//属性名:属性值
name:name,
age:age,
};
console.log(person);
//{ name: '徐华', age: 18 }
语法糖:
var name = "徐华";
var age = 18;
var person = {
name,
age,
};
console.log(person);
//{ name: '徐华', age: 18 }
速写方法
var person={
name:"张三",
age:22,
sayHello: function(){
console.log("你好");
},
};
person.sayHello()
//你好
语法糖
var person={
name:"张三",
age:22,
sayHello(){
console.log("你好");
},
};
person.sayHello()
//你好
模板字符串
var person = {
name: "上古",
age: 11,
};
var str1 = "my name is " + person.name + "\nmy age is " + person.age;
var str2 =`my name is ${person.name}
my age is ${person.age}`
console.log(str1);
console.log("===================")
console.log(str2);
/*
my name is 上古
my age is 11
===================
my name is 上古
my age is 11
*/