<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<a>a</a>
<script>
//数组去重
let arr = [2,3,4,5,3,2,3,4,7,8]
let arrAfter = Array.from(new Set(arr))
console.log(arrAfter)
//排序
//快速排序:复杂度:nlog2n 不稳定
var quickSort = function(arr) {
if (arr.length <= 1) {
return arr;
}
var middleIndex = Math.floor(arr.length/2)
var middle = arr.splice(middleIndex, 1)[0];
var left = []
var right = []
for (var i = 0; i < arr.length; i++){
if (arr < middle) {
left.push(arr[i])
} else {
right.push(arr[i])
}
}
return quickSort(left).concat([middle], quickSort(right))
}
//堆栈
//递归
//波兰式 逆波兰式
//es数组方法
obj.map(item => {
//判断item
if () {
let arr = []
arr.push(item))
return arr
}
})
obj.filter(item => {
//判断条件,直接返回符合要求的
item === a
})
//面向对象
//字面量
var o1 = {
name: 'o1'
}
var o1 = new Object({
name:'o1'
})
//函数
var F = function() {
this.name = 'o1'
}
var o1 = new F()
//
var Obj = {
name: 'o1'
}
var o1 = Object.created(Obj)
//new运算符
var obj = new Object()
obj.__proto__ = func.prototype
var k = func.call(this)
if (type k === 'object') {
return k
} else {
return obj
}
//类的实例化
function Animal() {
this.name = 'name'
}
class Animal2{
constructor() {
this.name = name
}
}
let a = new Animal()
let b = new Animal2()
//继承
//构造函数的方式
function Parent() {
this.name = 'parent'
}
function Child() {
Parent.call(this)
this.sex = 'boy'
}
let a = new Child(); console.log(a)
/*Child {name: "parent", sex: "boy"}
name: "parent"
sex: "boy"
__proto__: Object*/
//使用原型链继承
function Parent() {
this.name = 'parent'
}
function Child() {
this.sex = 'boy'
}
Child.prototype = new Parent()
console.log(Child.prototype)
console.log(Parent)
//组合继承
function Parent() {
this.name = 'parent'
}
function Child() {
Parent.call(this)
this.sex = 'boy'
}
Child.prototype = new Parent()
console.log(Child.prototype)
console.log(Parent)
//组合继承的优化1
function Parent() {
this.name = 'parent'
}
function Child() {
Parent.call(this)
this.sex = 'boy'
}
Child.prototype = Parent.prototype
//组合继承的优化2
function Parent() {
this.name = 'parent'
}
function Child() {
Parent.call(this)
this.sex = 'boy'
}
//创建中间对象的方法,区分开两个原型对象
Child.prototype = Object.create(parent.prototype)
Child.prototype.constructor = Child
</script>
</body>
</html>
测试
最新推荐文章于 2023-02-15 18:58:37 发布