te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - export default class Book extends Component VS export default Book - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - export default class Book extends Component VS export default Book - Stack Overflow

programmeradmin1浏览0评论

I'm new to react so its just a question that i want to know which one is more efficient and which give the best time plexity.

No. 1

    export default class BookingTabs extends Component {
  render() {
    return (
    );
  }
}

No. 2

class Book extends Component {
  render() {
    return (
    );
  }
}
export default Book

Questions:

  • which one is more efficient to use?
  • which one take less time? even difference in micro seconds?
  • what is the different between export default and module.export?

I'm new to react so its just a question that i want to know which one is more efficient and which give the best time plexity.

No. 1

    export default class BookingTabs extends Component {
  render() {
    return (
    );
  }
}

No. 2

class Book extends Component {
  render() {
    return (
    );
  }
}
export default Book

Questions:

  • which one is more efficient to use?
  • which one take less time? even difference in micro seconds?
  • what is the different between export default and module.export?
Share Improve this question asked Nov 15, 2017 at 8:58 niranjanshkniranjanshk 1471 gold badge3 silver badges11 bronze badges 1
  • 1 Even if any of them had an edge, it still would be a micro-optimisation. Each class gets exported only once. Do what's more readable and convenient. Remember that programming must be fun! – Robo Robok Commented Mar 15, 2018 at 15:44
Add a ment  | 

2 Answers 2

Reset to default 7

There is no difference between them. but when you want to use some high order ponent you should use second one. for example you want use "connect" for redux applications. you have to write

class Book extends Component {
  render() {
    return (
    );
  }
}
export default connect(Book)

* which one is more efficient to use?

They are equally efficient. It's a matter of coding style and preference.

No. 1 gives possibility to declare class without name such as

export default class extends Component {
  render() {
    return (
      <div>markup</div>
    );
  }
}

No. 2 gives possibilities for further working with the class before exporting it. Such as adding proptypes Book.propTypes = { /* prop-types defintion */} or used with higher order ponents.

* which one take less time? even difference in micro seconds?

Your target is probably for browsers which does not understand ES6 modules (import/export) natively. The piled code is the same. I would remend to play with https://babeljs.io/repl/ to get an idea what's is generated

* what is the different between export default and module.export?

The first is ES6 modules (to be understand by the browsers in the near future), the latter is NodeJS modules (https://nodejs/docs/latest/api/modules.html#modules_module). It's already well explained in Stackoverflow if you search around, e.g. https://stackoverflow./a/40295288/815507

发布评论

评论列表(0)

  1. 暂无评论