Giter Club home page Giter Club logo

Comments (4)

fantingsheng avatar fantingsheng commented on June 13, 2024

我在看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的知识

from just-now-qa.

WuChuanL avatar WuChuanL commented on June 13, 2024

我在看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,为什么不会报错呢?

from just-now-qa.

whyour avatar whyour commented on June 13, 2024

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

from just-now-qa.

WuChuanL avatar WuChuanL commented on June 13, 2024

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

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

from just-now-qa.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.