Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/extensions/admin_ui/media/javascript/esapi/Class.create.js
1154 views
1
/*
2
* Copyright (c) 2006-2025 Wade Alcorn - [email protected]
3
* Browser Exploitation Framework (BeEF) - https://beefproject.com
4
* See the file 'doc/COPYING' for copying permission
5
*/
6
7
/* Simple JavaScript Inheritance
8
* By John Resig http://ejohn.org/
9
* MIT Licensed.
10
*/
11
// Inspired by base2 and Prototype
12
(function(){
13
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
14
15
// The base Class implementation (does nothing)
16
this.Class = function(){};
17
18
// Create a new Class that inherits from this class
19
Class.extend = function(prop) {
20
var _super = this.prototype;
21
22
// Instantiate a base class (but only create the instance,
23
// don't run the init constructor)
24
initializing = true;
25
var prototype = new this();
26
initializing = false;
27
28
// Copy the properties over onto the new prototype
29
for (var name in prop) {
30
// Check if we're overwriting an existing function
31
prototype[name] = typeof prop[name] == "function" &&
32
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
33
(function(name, fn){
34
return function() {
35
var tmp = this._super;
36
37
// Add a new ._super() method that is the same method
38
// but on the super-class
39
this._super = _super[name];
40
41
// The method only need to be bound temporarily, so we
42
// remove it when we're done executing
43
var ret = fn.apply(this, arguments);
44
this._super = tmp;
45
46
return ret;
47
};
48
})(name, prop[name]) :
49
prop[name];
50
}
51
52
// The dummy class constructor
53
function Class() {
54
// All construction is actually done in the init method
55
if ( !initializing && this.init )
56
this.init.apply(this, arguments);
57
}
58
59
// Populate our constructed prototype object
60
Class.prototype = prototype;
61
62
// Enforce the constructor to be what we expect
63
Class.constructor = Class;
64
65
// And make this class extendable
66
Class.extend = arguments.callee;
67
68
return Class;
69
};
70
})();
71
72