Home > Web Front-end > JS Tutorial > Another way to convert js function declaration into function expression

Another way to convert js function declaration into function expression

巴扎黑
Release: 2016-11-25 11:11:33
Original
1040 people have browsed it

We know that to convert a function declaration expression into a function expression in js, you only need to add operators such as +,-,=,~ or ! or () in front of the function declaration.

In addition, you can also use the void operator for conversion. Here is a simple example:

Js code

void function(){console.log(1)}(); //1

void function(g) {console.log(g)}(this); //window

void is also commonly used in two places in project development:

1. Get the real undefined through void 0; 2. Replace a The href attribute of the element is set to javascript:void 0; to prevent page jumps.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template