var arr = [1, 2, 1];
Array.prototype.getRepeat = function () {
let obj = {}
for (let i = 0; i < this.length; i++) {
let item = this[i]
obj[item] = obj[item] + 1 || 1
}
return obj
}
console.log(arr.getRepeat())
var reg = /(http|https|file|ftp:\/\/)|(^\/\/)/
console.log(reg.test('//123'))
console.log(reg.test('ftp://123'))
console.log(reg.test('https://123'))
function a(callback) { setTimeout(callback, 2000, 'a') }
function b(callback) { setTimeout(callback, 2000, 'b') }
function c(callback) { setTimeout(callback, 30, 'c') }
function createPromise(handler) {
return new Promise(handler)
}
let aa = Promise.all([createPromise(a), createPromise(b)])
.then(res => {
console.log(res)
return createPromise(c)
})
.then(res => console.log(res))
console.log(aa)
function Person(name, age) {
this.name = name;
this.age = age;
}
Person.prototype.sayHello = function () {
console.log('hello world')
}
function Son(name, age) {
Person.call(this, name, age)
this.zi = '自身独有的数据'
}
Son.prototype = Object.create(Person.prototype)
Son.prototype.ziji = function () {
console.log('自己独有的,如果父元素也有这个方法,也不至于覆盖掉原有的,因为这方法存储在干净原型上,在渗透一层才到父元素那里')
}