aaaa
This commit is contained in:
58
teaching/lhj/kejian/js/yuanxing.html
Normal file
58
teaching/lhj/kejian/js/yuanxing.html
Normal file
@@ -0,0 +1,58 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
<script>
|
||||
// 构造函数
|
||||
function create(){
|
||||
this.role="admin"
|
||||
}
|
||||
// create()
|
||||
var obj= new create()
|
||||
// new 关键字的操作过程:
|
||||
// 1. 创建一个空对象
|
||||
// 2. 构造函数中的this指向这个 空对象
|
||||
// 3. 执行构造函数中的代码 给新对象添加属性和方法
|
||||
// 4. 返回这个新对象
|
||||
|
||||
|
||||
// 只要是个函数 都有prototype 属性
|
||||
// 只要是个对象 都有__proto__ 属性(左右两边都是两个下划线)
|
||||
// 这两个访问的都是对象的原型
|
||||
|
||||
// animal cat
|
||||
function animal(){
|
||||
this.run=function(){
|
||||
console.log("我跑得起来")
|
||||
}
|
||||
}
|
||||
var all=new animal()
|
||||
function cat(kind,hasmao,food){
|
||||
this.kind=kind;
|
||||
this.hasmao=hasmao;
|
||||
this.food=food;
|
||||
this.jiao=function(sheng){
|
||||
console.log(sheng)
|
||||
}
|
||||
}
|
||||
|
||||
var miao=new cat("哺乳类",1,"鱼")
|
||||
cat.prototype=all
|
||||
miao.run()
|
||||
|
||||
|
||||
// 顺序
|
||||
// 先写父级的构造函数
|
||||
// 创建父级对象
|
||||
// 写子级的构造函数
|
||||
// 指定子级的原型
|
||||
// 创建子级对象
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user