h函数如何运行,what h function?

135 阅读1分钟

**简单的实现一个h函数运行的过程,h means hyper text, hyper dom, whatever.. **

class VNode {
  constructor(options) {
    this.render = options.render;
  }

  static h(renderContent) {
    return 'renderContent is: ' + renderContent;
  }

  mount(targetId) {
    const targetDom = document.getElementById(targetId);
    targetDom.innerHTML = this.render(VNode.h);
  }
}

const node = new VNode({
  render: (h) => h('App'),
});

node.mount('container');

console.log('%c⧭', 'color: #40fff2', node);