Read nodejs together (2) ---- console and Timer (console & Timer)

Source: Internet
Author: User
Tags call back
Console stability: 4-APIforzen can print to stdout and stderr ). like the consoles provided by most web browsers, the console output in node is sent to the standard output stream and standard error stream. console. log ([...

Console)

Stability: 4-API forzen

It can print to stdout and stderr ). like the consoles provided by most web browsers, the console output in node is sent to the standard output stream and standard error stream.

Console. log ([data], [...])


In the standard output stream, a new row is printed. This method can support multiple parameters like printf (), for example, [javascript] view plaincopyprint?
Console. log ('count: % d', count );

Console. log ('count: % d', count );

If the formatted element is not found in the first string, node uses util. inspect to check each parameter. For more information, see util. format ()
Console.info ([data], [...])
Equivalent to the console. log () method.
Console. error ([data], [...])
Equivalent to the console. log () method. It is only printed to the standard error stream.
Console. warn ([data], [...])
Equivalent to the console. error () method.
Console. dir (obj)
Use uitl. inspect to check obj and print the result string to the standard output stream.
Console. time (label)
Mark a time point and start timing from this time point.
Console. timeEnd (label)
End the timer. Use the timer set by lable to print the console. time (label) to console. timeEnd (label) is the number of milliseconds used. For example, (in this example, if the value is 0 ms, I changed it to 5 SM after cycles): [javascript] view plaincopyprint?
Console. time ('2014-elements ');
For (var I = 0; I <100; I ++ ){
;
}
Console. timeEnd ('2014-elements ');

Console. time ('2014-elements ');
For (var I = 0; I <100; I ++ ){
;
}
Console. timeEnd ('2014-elements '); console. trace (label)
Print the stack tracing information at the current position to the standard error stream.
Console. assert (expression, [message])

Like the assert. OK () function, if the expression parameter is verified as false, an AssertionError error is thrown. The error message is the message parameter.


Timer (Timer)
Stability: 5-locked
All timer functions are global objects. You do not need to call the require () method to require them.
SetTimeout (callback, delay, [arg], [...])

Execution: Execute callback once after delay milliseconds. A timeoutId is returned for use in the clearTimeout () method. You can pass parameters to the callback function as needed.
It should be noted that your callback function may not be called exactly after delay milliseconds, and node cannot ensure that callback is triggered or required within a precise time.
The callback function will be triggered as close as possible to the specified time.
ClearTimeout (timeoutId)
Prevents a timeout event represented by timeoutId from being triggered.
SetInterval (callback, delay, [arg], [...])
Custom repeated execution-call back every time after delay milliseconds. An intervalId is returned to facilitate use in the clearInterval () method. You can pass parameters to the callback function as needed.
ClearInterval (intervalId)
Prevents an interval event represented by an intervalId from being triggered.

Related Article

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.