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 - Should use Class or Module in NodeJS - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Should use Class or Module in NodeJS - Stack Overflow

programmeradmin3浏览0评论

I'm newbie on NodeJS. I'm researching about the inheritance on NodeJS and found there's an inheritance using Class (on ES6). I have some questions about the using of the Class and Module to decide which one should be used in my case:

  1. As I know, "Module" is cached after i run once, it means I don't need to initial every time, and for "Class" which i need to initial every time I use it. So does it make a leak memory or not good for performance?
  2. In my case, i would like to implement the inheritance for some mon functions, then i can reuse them in my child. In case using "Class": If there are multiple request sent from Client side at the same time, does it affect to the Server's performance such as the slower's response or anything?
  3. If using "CLASS", can I trigger ONCE for a global function( Any other inheritance classes will not trigger that function.)
  4. After create an instance of Class and processing the functionality, will it be released?

Thanks in advance.

I'm newbie on NodeJS. I'm researching about the inheritance on NodeJS and found there's an inheritance using Class (on ES6). I have some questions about the using of the Class and Module to decide which one should be used in my case:

  1. As I know, "Module" is cached after i run once, it means I don't need to initial every time, and for "Class" which i need to initial every time I use it. So does it make a leak memory or not good for performance?
  2. In my case, i would like to implement the inheritance for some mon functions, then i can reuse them in my child. In case using "Class": If there are multiple request sent from Client side at the same time, does it affect to the Server's performance such as the slower's response or anything?
  3. If using "CLASS", can I trigger ONCE for a global function( Any other inheritance classes will not trigger that function.)
  4. After create an instance of Class and processing the functionality, will it be released?

Thanks in advance.

Share Improve this question asked Jun 23, 2018 at 17:26 HTKT89HTKT89 912 silver badges6 bronze badges 1
  • I remend doing more research on the basics of JavaScript, and separately of Node.js. – T.J. Crowder Commented Jun 23, 2018 at 17:35
Add a ment  | 

1 Answer 1

Reset to default 15

Should use Class or Module in NodeJS

This is a false choice. You may well use both. You certainly want to use modules (in fact, it would be very hard not to). You may or may not want to use class (more in this question's answers), and if you don't you may or may not want to use pseudo-classical inheritance; or you might prefer to directly use prototypical inheritance. That's a style choice.

1. As I know, "Module" is cached after i run once...

Yes, modules are cached. You use the inline code of a module to do its initialization. Then the module exports functions and/or constructor functions (loosely, "classes"), etc., that other modules can use.

2. ... If there are multiple request sent from Client side at the same time, does it affect to the Server's performance such as the slower's response or anything?

Creating objects, including creating objects via constructor functions, is very fast. Worry about functionality and maintainability. Worry about performance if and when there's a problem.

3. If using "CLASS", can I trigger ONCE for a global function( Any other inheritance classes will not trigger that function.)

You can create a single instance of a class and export it from a module for reuse without being re-created, yes.

4. After create an instance of Class and processing the functionality, will it be released?

If nothing keeps a reference to an object, the object is eligible for garbage collection, yes. Naturally, if something keeps a reference to the object (for instance, if you export it from a module), it isn't eligible for garbage collection.

发布评论

评论列表(0)

  1. 暂无评论