Nodejs Global Objects

Source: Internet
Author: User

1. Five methods for global Object console: Log dir time timeend error

2. The Consle object is defined in the Global Object window in the front-end

3. In Nodejs, the global object is globally and the console is defined in global.

4. SetInterval is also a global object defined in global

5. SetTimeout is also a global object defined in global

6. __dirname is also a global object that represents the path where the current file resides

7. __filename is also a global object that represents the path where the current file is located (plus the name of the file)

8. Exports is the exposure require is quoted

9. Module exposure Moudle has a property of exports

Small summary: Global objects in node: Console setinteval setTimeout __dirname __filename require exports module

Small summary: What is exposed in node: variables, objects, functions, constructors, factory methods

Exposure with the Module property allows you to add properties without adding attributes

If the module adds a property, the content of the exposure is the same as the exports exposure

1 Exposure variables

Exports.a=a

Module.exports=a

2 Exposure Object

Var A={a:1}

Module.exports=a

3 Exposure function

Function foo () {

Console. Log (' Hello ')

}

Module.exports=foo

4 Exposure constructor

5 Exposure Factory method

What is a factory method

(1 ) using the new object Creating Objects

(2 ) Use return in the function return This object

The factory method does not need to use new object is created

Because the factory method was exposed in the b.js, the obj here is the factory method

Calling this factory method will put back an object

1 Reference exposure function

Console.log (obj)

2 Reference exposure function

Because a function is stored, obj is the function that exposes it.

3 constructors that reference exposure

Because B.js is a construction method, this is where obj is a construction method

Nodejs Global Objects

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.