-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsUtil.js
More file actions
41 lines (41 loc) · 1.06 KB
/
Copy pathjsUtil.js
File metadata and controls
41 lines (41 loc) · 1.06 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
//工具方法
tool={
inherit:function(target,origin){
target.prototype=Object.create(origin.prototype)
target.prototype.constructor=target
},
extends:function(origin){
var result=function(){
origin.apply(this,arguments)
};
this.inherit(result,origin)
return result
},
single:function(origin){
var singleResult=(function(){
var instance=null
return function(){
if(instance){
return instance
}else{
origin&&origin.apply(this,arguments)
instance=this
}
}
})()
origin&&this.inherit(singleResult,origin)
return singleResult
}
}
// function Square(x,y,width,height){
// this.x=x;
// this.y=y;
// this.width=width;
// this.height=height;
// }
// Square.prototype.touch=function(){
// console.log(111)
// }
// var Food=tool.single(Square)
// var f1=new Food(10,20,200,100);
// var f2=new Food(20,20,200,200);