Nodejs's Util tool

Source: Internet
Author: User

Util is a core module of Nodejs, used to provide a collection of commonly used functions

1.util.inherits (Implementing object prototype inheritance)

Summary: JS inheritance is based on the prototype, and itself does not inherit the language characteristics, simply by copying the way to implement the original object.

First, in the NODEJS environment to introduce the Util module

Const UTIL = require (' util ');

Ii. inheritance

function Sayname () {

this.name = ' Joink ';

This.say = function () {Console.log (this.name)};

}

function SetName () {

this.name = ' Lebron ';

}

Now you want the function SetName to inherit sayname methods and properties.

Util.inherits (Setname,sayname); SetName Inheritance Sayname

At this point, the new one sayname, and executes the inside properties, methods, will find that nothing changes.

But, new one setname try. It will be found that this object has all the methods of Sayname, and name has been changed. Here is an example

  

Nodejs's Util tool

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.