We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
本文为读 lodash 源码的第一百九十六篇,后续文章会更新到这个仓库中,欢迎 star:pocket-lodash
gitbook也会同步仓库的更新,gitbook地址:pocket-lodash
import isPrototype from './isPrototype.js'
《lodash源码分析之isPrototype》
initCloneObject 的作用是初始化一个空对象,但是这个空对象会继承传入对象 object 的原型链。
initCloneObject
object
源码如下:
function initCloneObject(object) { return (typeof object.constructor === 'function' && !isPrototype(object)) ? Object.create(Object.getPrototypeOf(object)) : {} }
首先判断 object.constructor 是否为 function ,如果为 function 则表示这个对象上可能存在原型链,同时也要将原型对象排除。如果满足这个条件,则使用 Object.getPrototypeOf 去获取 object 上的原型对象,并用 Object.create 创建一个新对象,这个新对象会继承 object 的原型链。
object.constructor
function
Object.getPrototypeOf
Object.create
否则直接返回一个空对象。
署名-非商业性使用-禁止演绎 4.0 国际 (CC BY-NC-ND 4.0)
最后,所有文章都会同步发送到微信公众号上,欢迎关注,欢迎提意见:
作者:对角另一面
The text was updated successfully, but these errors were encountered:
No branches or pull requests
本文为读 lodash 源码的第一百九十六篇,后续文章会更新到这个仓库中,欢迎 star:pocket-lodash
gitbook也会同步仓库的更新,gitbook地址:pocket-lodash
依赖
《lodash源码分析之isPrototype》
源码分析
initCloneObject
的作用是初始化一个空对象,但是这个空对象会继承传入对象object
的原型链。源码如下:
首先判断
object.constructor
是否为function
,如果为function
则表示这个对象上可能存在原型链,同时也要将原型对象排除。如果满足这个条件,则使用Object.getPrototypeOf
去获取object
上的原型对象,并用Object.create
创建一个新对象,这个新对象会继承object
的原型链。否则直接返回一个空对象。
License
署名-非商业性使用-禁止演绎 4.0 国际 (CC BY-NC-ND 4.0)
最后,所有文章都会同步发送到微信公众号上,欢迎关注,欢迎提意见:
作者:对角另一面
The text was updated successfully, but these errors were encountered: