refactor: 减少全局变量 调试require选项

This commit is contained in:
coding
2017-10-17 02:53:51 +00:00
parent b668795518
commit 5b621d3d99
3 changed files with 37 additions and 47 deletions

View File

@ -3,28 +3,31 @@
*/
/*global base*/
var log = base.getLog().static;
var Level = Java.type('java.util.logging.Level');
var Console = function (name) {
this.name = name ? '[' + name + '] ' : '';
Object.defineProperty(this, 'name', {
get: function () {
return this._name;
}.bind(this),
set: function (name) {
this._name = name ? '[' + name + '] ' : '';
}.bind(this)
});
this.log = function () {
log.i(this.name + Array.prototype.join.call(arguments, ' '));
},
this.warn = function () {
log.w(this.name + Array.prototype.join.call(arguments, ' '));
},
this.error = function () {
log.log(Level.SEVERE, this.name + Array.prototype.join.call(arguments, ' '));
},
this.debug = function () {
log.d(this.name + Array.prototype.join.call(arguments, ' '));
(function(global){
var Level = Java.type('java.util.logging.Level');
var Console = function (name) {
Object.defineProperty(this, 'name', {
get: function () {
return this._name;
}.bind(this),
set: function (name) {
this._name = name ? '[' + name + '] ' : '';
}.bind(this)
});
this.name = name;
this.log = function () {
log.i(this.name + Array.prototype.join.call(arguments, ' '));
},
this.warn = function () {
log.w(this.name + Array.prototype.join.call(arguments, ' '));
},
this.error = function () {
log.log(Level.SEVERE, this.name + Array.prototype.join.call(arguments, ' '));
},
this.debug = function () {
log.d(this.name + Array.prototype.join.call(arguments, ' '));
}
}
}
global.console = new Console();
global.Console = Console;
global.console = new Console();
})(global)