标签:bdd turn 练习题 asc 介绍 test 程序员 lin 构造
通过extends关键字实现
const obj = {
id:123,
age:20,
name:"cyrus",
school:"河北科技大学"
}
let obj1 = {
age:18,
const promise = new Promise((resolve, reject) => {
console.log(1);
resolve(3);
console.log(2);
reject(4)
})
promise.then((res) => {
console.log(res);
}).catch(err=>{
console.log(err);
})
console.log(5);
// 1 2 5 3
let name = Symbol(‘name‘)
let name1 = Symbol.for(‘name‘)
console.log(name == name1);// false
function * gen(){
let params = yield 2
let params1 = yield 3
let params2 = yield params1 + 6
let params3 = yield 7
return params2 * params + params3
}
let lt = gen();
console.log(lt.next());// { value: 2, done: false }
console.log(lt.next(3)); // { value: 3, done: false }
console.log(lt.next(lt.next(1).value))// { value: 7, done: false }
console.log(lt.next(4));// { value: 25, done: true }
let obj = {name:"张三",age:16}
let proxy = new Proxy(obj,{
get(target,property){
if(target.age < 18){
return "未成年人"
}
return target[property]
},
set(target,property,value){
if(property == ‘name‘&&target.age< 18){
console.log("未成年人不允许改名字");
}
target[property] = value
}
})
console.log(proxy.name);
proxy.name = "李四"
console.log(proxy.name);
proxy.age = 20
console.log(proxy.name);
//未成年人
//未成年人不允许改名字
//未成年人
//李四
let a=5;
let b=3;
[a,b]=[b,a]
console.log(a);
console.log(b);
let name = Symbol()
let obj = {
name:"李白",
[name]:"杜甫"
}
Reflect.ownKeys(obj).forEach(key=>{
console.log(key);
console.log(obj[key])
})
let list = [1,3,4,6,2,2,2,3,1,2,3,4]
let set = new Set(list)
let newList = Array.from(set)
// a.js
默认导出
const test = "测试"
export default {
name:"李白",
age:18,
test
}
普通导出
export function getName(){
console.log(123)
}
export const cat = "皮皮"
// b.js
默认导入
import aObj from ‘./a.js‘
console.log(aObj.name) //李白
普通导入
import {getName,cat} from ‘./a.js‘
console.log(cat)
getName()
const list = [
{id:3,name:"张三丰"},
{id:5,name:"张无忌"},
{id:13,name:"杨逍"},
{id:33,name:"殷天正"},
{id:12,name:"赵敏"},
{id:97,name:"周芷若"},
]
console.log(list.filter(item => item.name.startsWith("杨")))
console.log(list.filter(item => item.name.includes("天")))
console.log(list.find(item => item.name == ‘周芷若‘).id)
const list = [
{id:3,name:"张三丰"},
{id:5,name:"张无忌"},
{id:13,name:"杨逍"},
{id:33,name:"殷天正"},
{id:12,name:"赵敏"},
{id:97,name:"周芷若"},
]
console.log(list.map(item=>({
const roleList = [{
id: 1,
name: ‘老板‘
}, {
id: 2,
name: ‘经理‘
}, {
id: 3,
name: ‘运营总监‘
}, {
id: 4,
name: ‘CEO‘
}, {
id: 5,
name: ‘销售‘
}, {
id: 6,
name: ‘实施‘
}, {
id: 7,
name: ‘程序员‘
}, {
id: 8,
name: ‘UI工程师‘
}, {
id: 9,
name: ‘产品经理‘
}];
// 用户已选择的数组
const selectedRoleList = [{
id: 2,
name: ‘经理‘
}, {
id: 3,
name: ‘运营总监‘
}, {
id: 6,
name: ‘实施‘
}, {
id: 7,
name: ‘程序员‘
}, {
id: 9,
name: ‘产品经理‘
}];
const unSelectedRoles = roleList.filter(item => !selectedRoleList.some(selectedItem => selectedItem.id == item.id))
console.log(unSelectedRoles);
const selectedIds = selectedRoleList.map(item=>