-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathorm.html
67 lines (53 loc) · 1.11 KB
/
orm.html
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
59
60
61
62
63
64
65
66
67
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ORM</title>
</head>
<body>
<script type="text/javascript">
var Model = {
inherited : function(){},
created: function(){},
prototype: {},
create: function(){
var object = Object.create(this)
object.parent = this
object.prototype = object.fn = Object.create(this.prototype)
object.created()
this.inherited(object)
return object
},
init: function(){
var instance = Object.create(this.prototype)
instance.parent = this
instance.init.apply(instance, arguments)
return instance
},
extend: function(o){
var extended = o.extended
for(var key in o){
this[key] = o[key]
}
if(extended) extended(this)
},
include: function(o){
var included = o.included
for(var key in o){
this.prototype[key] = o[key]
}
if(included) included(this)
}
}
Model.extend({
find: function(){}
})
Model.include({
init: function(a){console.log(a)},
load : function(attributes){}
})
var Asset = Model.create()
var asset = Asset.init({name: 'foo.png'})
</script>
</body>
</html>