MVCベースのJagaScript Webリッチアプリケーション開発
9086 ワード
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title> MVC JagaScript Web </title>
<script>
var Class = function () {
var klass = function () {
this.init.apply(this, arguments);
};
klass.prototype.init = function () {};
// prototype
klass.fn = klass.prototype;
//
klass.fn.parent = klass;
//
klass.extend = function (obj) {
var extended = obj.extended;
for (var i in obj) {
klass[i] = obj[i];
}
if (extended) extended(klass);
};
//
klass.include = function (obj) {
var included = obj.included;
for (var i in obj) {
klass.fn[i] = obj[i];
}
if (included) included(klass);
};
return klass;
};
/*
// ,
var Person = new Class;
Person.extend({
find: function (id) { alert(id); },
exists: function (id) {}
});
var person = Person.find(1);
*/
// , (prototype)
var Person = new Class;
Person.include({
save: function () {},
destroy: function () {}
});
var person = new Person;
person.save();
// extended included 。
Person.extend({
extended: function (klass) {
console.log(klass, ' was extended!');
}
});
</script>
</head>
<body>
</body>
</html>