create.js
980 Bytes
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
define(["../_base/lang"], function(lang){
return function(name, ctor, base, props){
base = base || Error;
var ErrorCtor = function(message){
if(base === Error){
if(Error.captureStackTrace){
Error.captureStackTrace(this, ErrorCtor);
}
// Error.call() operates on the returned error
// object rather than operating on |this|
var err = Error.call(this, message),
prop;
// Copy own properties from err to |this|
for(prop in err){
if(err.hasOwnProperty(prop)){
this[prop] = err[prop];
}
}
// messsage is non-enumerable in ES5
this.message = message;
// stack is non-enumerable in at least Firefox
this.stack = err.stack;
}else{
base.apply(this, arguments);
}
if(ctor){
ctor.apply(this, arguments);
}
};
ErrorCtor.prototype = lang.delegate(base.prototype, props);
ErrorCtor.prototype.name = name;
ErrorCtor.prototype.constructor = ErrorCtor;
return ErrorCtor;
};
});