//定时执行并返回pormise
function a(fn, ms) {
return new Promise((reso, sule) => {
setTimeout(() => {
fn()
}, ms)
})
}
//id自增
function getid2() {
this.id = this.id || 0
this.id++
return this.id
}
//对象遍历
function additem(obj) {
let list = []
for (var [key, value] in obj) {
let obj2 = {}
obj2[key] = obj[key]
console.log(key, obj[key])
}
return list
}
//定时执行
function fun(fn, time, wait) {
var times = setInterval(() => {
if (time == 0) {
clearInterval(times)
} else {
time--
fn()
}
}, wait)
}
//遍历树
var datas = Array(datas)
var list = []
function getid(treeData, arr) {
treeData.forEach((ele) => {
list.push(ele.labml)
if (ele.chidren && ele.chidren.length > 0) {
getid(ele.chidren, arr)
}
})
}
getid(datas, list)
//增加一个数组去重方法
Array.prototype.tem = function() {
console.log(this)
return [...new Set(this)]
}