Skip to content
New issue

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

Vue源码 #11

Open
WuChuanL opened this issue Jun 17, 2021 · 4 comments
Open

Vue源码 #11

WuChuanL opened this issue Jun 17, 2021 · 4 comments

Comments

@WuChuanL
Copy link

我在看Vue2.x源码的时候,发现文件是js文件,但是里面出现了:数据类型这种写法,我不是很懂,希望老师能讲解一下。
文件 src/core/vdom/create-element.js

export function createElement (
  context: Component,
  tag: any,
  data: any,
  children: any,
  normalizationType: any,
  alwaysNormalize: boolean
): VNode | Array<VNode> {
  if (Array.isArray(data) || isPrimitive(data)) {
    normalizationType = children
    children = data
    data = undefined
  }
  if (isTrue(alwaysNormalize)) {
    normalizationType = ALWAYS_NORMALIZE
  }
  return _createElement(context, tag, data, children, normalizationType)
}

我没有见过这种写法,这种写法为什么不会报错?为什么要这样写?

@fantingsheng
Copy link

我在看Vue2.x源码的时候,发现文件是js文件,但是里面出现了:数据类型这种写法,我不是很懂,希望老师能讲解一下。
文件 src/core/vdom/create-element.js

export function createElement (
  context: Component,
  tag: any,
  data: any,
  children: any,
  normalizationType: any,
  alwaysNormalize: boolean
): VNode | Array<VNode> {
  if (Array.isArray(data) || isPrimitive(data)) {
    normalizationType = children
    children = data
    data = undefined
  }
  if (isTrue(alwaysNormalize)) {
    normalizationType = ALWAYS_NORMALIZE
  }
  return _createElement(context, tag, data, children, normalizationType)
}

我没有见过这种写法,这种写法为什么不会报错?为什么要这样写?

这是TypeScript的语法,可以学学Ts的知识

@WuChuanL
Copy link
Author

我在看Vue2.x源码的时候,发现文件是js文件,但是里面出现了:数据类型这种写法,我不是很懂,希望老师能讲解一下。
文件 src/core/vdom/create-element.js

export function createElement (
  context: Component,
  tag: any,
  data: any,
  children: any,
  normalizationType: any,
  alwaysNormalize: boolean
): VNode | Array<VNode> {
  if (Array.isArray(data) || isPrimitive(data)) {
    normalizationType = children
    children = data
    data = undefined
  }
  if (isTrue(alwaysNormalize)) {
    normalizationType = ALWAYS_NORMALIZE
  }
  return _createElement(context, tag, data, children, normalizationType)
}

我没有见过这种写法,这种写法为什么不会报错?为什么要这样写?

这是TypeScript的语法,可以学学Ts的知识

这里的文件类型是.js,不是.ts,为什么不会报错呢?

@whyour
Copy link

whyour commented Jun 22, 2021

flowjs了解下,文件最上面有注释

@WuChuanL
Copy link
Author

flowjs了解下,文件最上面有注释

多谢解答,在很多地方问过,您的解答是最标准的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants