/
so_class.js
51 lines (44 loc) · 1.22 KB
/
so_class.js
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
/**
* @package so
* @object so.class
* @depends so
* @author Kerem Güneş
* @license The MIT License <https://opensource.org/licenses/MIT>
*/
;(function ($) { 'use strict';
var PROTOTYPE = 'prototype', $extend = $.extend;
/**
* Class.
* @param {Function} subClass
* @return {Object}
*/
var $class = function (subClass) {
return {
/**
* Extends.
* @param {Function} supClass
* @return {Function}
*/
extends: function (supClass) {
// @note: super() always must be called in subClass constructor
var prototype = $extend(
{}, supClass[PROTOTYPE], subClass[PROTOTYPE],
{constructor: subClass, super: supClass}
);
subClass[PROTOTYPE] = Object.create(prototype);
return subClass;
}
}
};
/**
* Extend.
* @param {Function} target
* @param {Object} prototype
* @return {Function}
*/
$class.extend = function (target, prototype) {
return $extend(target[PROTOTYPE], prototype);
},
// export
$.class = $class;
})(window.so);