-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a64449
commit 579c470
Showing
5 changed files
with
103 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ | |
"rollup-plugin-node-resolve": "3.0.3" | ||
}, | ||
"dependencies": { | ||
"@jsmini/is": "0.7.1", | ||
"babel-runtime": "6.26.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,80 @@ | ||
import { yan } from './test.js'; | ||
@import { isBoolean, isObject, isArray } from '@jsmini/is'; | ||
|
||
import yan2 from './test.js'; | ||
// Object.create(null) 的对象,没有hasOwnProperty方法 | ||
function hasOwnProp(obj, key) { | ||
return Object.prototype.hasOwnProperty.call(obj, key); | ||
} | ||
|
||
console.log(yan); | ||
console.log(yan2); | ||
export function assign(target, ...sourceList) { | ||
if (!isObject(target)) { | ||
throw new TypeError('assign first param must is object'); | ||
} | ||
|
||
var a = 1 + 1; | ||
var b = a; | ||
console.log(a); | ||
console.log(b); | ||
for (let i = 0; i < sourceList.length; i++) { | ||
const source = sourceList[i]; | ||
|
||
export const name = 'base'; | ||
if (isObject(source)) { | ||
for(let key in source) { | ||
if (hasOwnProp(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return target; | ||
} | ||
|
||
export function extend(deep, target, ...sourceList) { | ||
if (isObject(deep)) { | ||
deep = false; | ||
sourceList.unshift(target); | ||
target = deep; | ||
} else { | ||
deep = !!deep; | ||
} | ||
|
||
|
||
// 浅拷贝 | ||
if (!deep) { | ||
return assign(target, ...sourceList); | ||
} | ||
|
||
// 深拷贝 | ||
if (!isObject(target)) { | ||
throw new TypeError('extend target param must is object'); | ||
} | ||
|
||
for (let i = 0; i < sourceList.length; i++) { | ||
const source = sourceList[i]; | ||
for (let name in source) { | ||
const src = target[name]; | ||
const copy = source[name]; | ||
|
||
//避免无限循环 | ||
if (target === copy) { | ||
continue; | ||
} | ||
|
||
// 非可枚举属性 | ||
if (!hasOwnProp(source, name)) { | ||
continue; | ||
} | ||
|
||
let copyIsArr; | ||
if (copy && (isObject(copy) || (copyIsArr = isArray(copy)))) { | ||
let clone; | ||
if (copyIsArr) { | ||
clone = src && isArray(src) ? src : []; | ||
} else { | ||
clone = src && isObject(src) ? src : {}; | ||
} | ||
target[name] = extend(true, clone, copy); | ||
} else if (typeof copy !== 'undefined'){ | ||
target[name] = copy; | ||
} | ||
} | ||
} | ||
|
||
return target; | ||
} |
This file was deleted.
Oops, something went wrong.