feat: 调整基础类库加载

This commit is contained in:
coding
2017-12-28 08:28:13 +00:00
parent f164f7dd42
commit 9ef64d9bc2
5 changed files with 68 additions and 26 deletions

View File

@ -3,24 +3,6 @@
*/
(function () {
// Java格式化方法
var str = Java.type('java.lang.String');
String.prototype.format = function () {
return str.format(this, Array.prototype.slice.call(arguments, 0))
};
// ========== 暂不扩展Object ==========
// // JSON快捷方法
// Object.prototype.toJson = function () {
// return JSON.stringify(this);
// };
// // YAML快速生成
// var yaml = require('modules/yaml');
// Object.prototype.toYaml = function () {
// return yaml.safeDump(this);
// };
/**
* 日期格式化
* : new Date().format('yyyy-MM-dd hh:mm:ss.s') => "2017-08-24 16:15:40.693"

View File

@ -0,0 +1,50 @@
/**
* 补丁和方法扩展
*/
(function () {
// Object.assign Polyfill
if (!Object.assign) {
Object.defineProperty(Object, "assign", {
enumerable: false,
configurable: true,
writable: true,
value: function(target) {
"use strict";
if (target === undefined || target === null)
throw new TypeError("Cannot convert first argument to object");
var to = Object(target);
for (var i = 1; i < arguments.length; i++) {
var nextSource = arguments[i];
if (nextSource === undefined || nextSource === null) continue;
var keysArray = Object.keys(Object(nextSource));
for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
var nextKey = keysArray[nextIndex];
var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
if (desc !== undefined && desc.enumerable) to[nextKey] = nextSource[nextKey];
}
}
return to;
}
});
}
// // JSON快捷方法
if(!Object.toJson){
Object.defineProperty(Object, "toJson", {
enumerable: false,
value: function() {
return JSON.stringify(this);
}
});
}
// Object.prototype.toJson = function () {
// return JSON.stringify(this);
// };
// // YAML快速生成
// var yaml = require('modules/yaml');
// Object.prototype.toYaml = function () {
// return yaml.safeDump(this);
// };
})();

View File

@ -0,0 +1,11 @@
/**
* 补丁和方法扩展
*/
(function () {
// Java格式化方法
var str = Java.type('java.lang.String');
String.prototype.format = function () {
return str.format(this, Array.prototype.slice.call(arguments, 0))
};
})();