|
@@ -4,7 +4,7 @@
|
|
* @param {...any} args
|
|
* @param {...any} args
|
|
* @returns
|
|
* @returns
|
|
*/
|
|
*/
|
|
-function newInstance(Fn,...args){
|
|
|
|
|
|
+export function newInstance(Fn,...args){
|
|
const obj = {}
|
|
const obj = {}
|
|
const result = Fn.call(obj,...args)
|
|
const result = Fn.call(obj,...args)
|
|
obj.__proto__ = Fn.prototype
|
|
obj.__proto__ = Fn.prototype
|
|
@@ -16,7 +16,7 @@ function newInstance(Fn,...args){
|
|
* @param {*} Fn
|
|
* @param {*} Fn
|
|
* @returns
|
|
* @returns
|
|
*/
|
|
*/
|
|
-function myInstanceOf(obj,Fn){
|
|
|
|
|
|
+export function myInstanceOf(obj,Fn){
|
|
let prototype = Fn.prototype
|
|
let prototype = Fn.prototype
|
|
let proto = obj.__proto__
|
|
let proto = obj.__proto__
|
|
while(proto){
|
|
while(proto){
|
|
@@ -32,7 +32,7 @@ function myInstanceOf(obj,Fn){
|
|
* @param {...any} objs
|
|
* @param {...any} objs
|
|
* @returns
|
|
* @returns
|
|
*/
|
|
*/
|
|
-function mergeObject(...objs){
|
|
|
|
|
|
+export function mergeObject(...objs){
|
|
const result = {}
|
|
const result = {}
|
|
objs.forEach(obj =>{
|
|
objs.forEach(obj =>{
|
|
//获取所有属性
|
|
//获取所有属性
|
|
@@ -52,7 +52,7 @@ function mergeObject(...objs){
|
|
* @param {*} target
|
|
* @param {*} target
|
|
* @returns
|
|
* @returns
|
|
*/
|
|
*/
|
|
-function clone1(target){
|
|
|
|
|
|
+export function clone1(target){
|
|
if(typeof target === 'object' && target !== null){
|
|
if(typeof target === 'object' && target !== null){
|
|
if(Array.isArray(target)){
|
|
if(Array.isArray(target)){
|
|
return [...target]
|
|
return [...target]
|
|
@@ -67,7 +67,7 @@ function clone1(target){
|
|
* @param {*} target
|
|
* @param {*} target
|
|
* @returns
|
|
* @returns
|
|
*/
|
|
*/
|
|
- function clone2(target){
|
|
|
|
|
|
+ export function clone2(target){
|
|
if(typeof target === 'object' && target !== null){
|
|
if(typeof target === 'object' && target !== null){
|
|
//创建容器
|
|
//创建容器
|
|
const result = Array.isArray(target)?[]:{}
|
|
const result = Array.isArray(target)?[]:{}
|
|
@@ -87,7 +87,7 @@ function clone1(target){
|
|
* @param {*} target
|
|
* @param {*} target
|
|
* @returns
|
|
* @returns
|
|
*/
|
|
*/
|
|
-function deepClone1(target){
|
|
|
|
|
|
+export function deepClone1(target){
|
|
return JSON.parse(JSON.stringify(target))
|
|
return JSON.parse(JSON.stringify(target))
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
@@ -95,7 +95,7 @@ function deepClone1(target){
|
|
* @param {*} target
|
|
* @param {*} target
|
|
* @returns
|
|
* @returns
|
|
*/
|
|
*/
|
|
-function deepClone2(target){
|
|
|
|
|
|
+export function deepClone2(target){
|
|
if(typeof target === 'object' && target !== null){
|
|
if(typeof target === 'object' && target !== null){
|
|
const result = Array.isArray(target)?[]:{}
|
|
const result = Array.isArray(target)?[]:{}
|
|
for(let key in target){
|
|
for(let key in target){
|
|
@@ -115,7 +115,7 @@ function deepClone2(target){
|
|
* @param {*} map
|
|
* @param {*} map
|
|
* @returns
|
|
* @returns
|
|
*/
|
|
*/
|
|
- function deepClone2(target,map = new Map()){
|
|
|
|
|
|
+ export function deepClone3(target,map = new Map()){
|
|
if(typeof target === 'object' && target !== null){
|
|
if(typeof target === 'object' && target !== null){
|
|
let cache = map.get(target)
|
|
let cache = map.get(target)
|
|
if(cache) return cache
|
|
if(cache) return cache
|
|
@@ -138,7 +138,7 @@ function deepClone2(target){
|
|
* @param {*} map
|
|
* @param {*} map
|
|
* @returns
|
|
* @returns
|
|
*/
|
|
*/
|
|
- function deepClone2(target,map = new Map()){
|
|
|
|
|
|
+ export function deepClone4(target,map = new Map()){
|
|
if(typeof target === 'object' && target !== null){
|
|
if(typeof target === 'object' && target !== null){
|
|
let cache = map.get(target)
|
|
let cache = map.get(target)
|
|
if(cache) return cache
|
|
if(cache) return cache
|