How to use the inherits function from util

Find comprehensive JavaScript util.inherits code examples handpicked from public code repositorys.

342
343
344
345
346
347
348
349
350
351
util.format(1, 2, 3); // '1 2 3'
```


<div id="inherits" class="anchor"></div>
## util.inherits(constructor, superConstructor)

从一个[构造函数](https://developer.mozilla.org/zh-CN/JavaScript/Reference/Global_Objects/Object/constructor)中继承一个原型方法到另一个。`constructor` 的属性会被设置到从 `superConstructor` 创建的新对象上。

另外的好处是,`superConstructor` 将可以通过 `constructor.super_` 属性访问。
fork icon21
star icon99
watch icon2

18
19
20
21
22
23
24
25
26
27
28
 *
 * @returns {Object}
 */
exports.inherits = function (constructor, superConstructor)
{
  return util.inherits.apply(util, arguments);
};


/**
 * Note: A simple wrapper around util.format() for now, but this will likely
fork icon84
star icon80
watch icon16

18
19
20
21
22
23
24
25
26
27
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

var util = require('util');
var EventEmitter = require('events');
var inherits = util.inherits;

// communicate with events module, but don't require that
// module to have to load this one, since this module has
// a few side effects.
fork icon0
star icon9
watch icon2

4
5
6
7
8
9
10
11
12
13
// No new pull requests targeting this module will be accepted
// unless they address existing, critical bugs.

const util = require('util');
const EventEmitter = require('events');
const inherits = util.inherits;

// communicate with events module, but don't require that
// module to have to load this one, since this module has
// a few side effects.
fork icon0
star icon0
watch icon2