-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9-classAndmodule.html
More file actions
58 lines (53 loc) · 1.15 KB
/
9-classAndmodule.html
File metadata and controls
58 lines (53 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<script type="text/javascript">
/**
* 9.2.2 counstructor属性
*/
(function(){
function Fun(){
this.sname ="wq";
};
// 这里的构造函数都是重写的,如果没重写他将会继承Object的原型,
Fun.prototype = {
constructor: Fun,
say: function(){},
fill: function(){},
}
var fun = new Fun();
// console.log(fun, "fun");
})();
//关于bind方法的理解: es5中bind方法返回的函数是没有prototype属性的, (我们自己写的是有的)
(function(){
// function fun(sname){
// this.sname=sname;
// return this;
// };
// var obj ={
// sname:"wqwqwqw",
// sage:"12",
// };
// var f = fun.bind(obj);
// console.log(f,"F");
// console.log(new f(),"ff");
})();
(function(){
var obj = {"sname":"wq"};
function fun(sname){
this.sname = sname
}
fun.prototype = {
say:function(){}
}
var Bind = fun.bind(obj);
// console.log(Bind.prototype,"Bind");
// console.log(new Bind("wangqi"),"Bind")
})();
(function(){
function fun(){};
fun.prototype ={
say:function(){}
}
var f = new fun();
var p;
console.log(fun.prototype.isPrototypeOf(f));
})();
</script>