Home > Web Front-end > JS Tutorial > How to get the current method name in javascript

How to get the current method name in javascript

王林
Release: 2021-10-25 15:24:44
Original
4445 people have browsed it

Javascript method to get the current method name: [function tuzisir() {var tmp = arguments.callee.toString();var re = /function\s*(\w*)/i;var ma. ..].

How to get the current method name in javascript

#The operating environment of this article: windows10 system, javascript 1.8.5, thinkpad t480 computer.

The specific implementation code for javascript to obtain the current method name is as follows:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<span onclick="tuzisir()">点我</span>
</body>
</html>
<script>
    function tuzisir() {
        var tmp = arguments.callee.toString();
        var re = /function\s*(\w*)/i;
        var matches = re.exec(tmp);//方法名
        var id=matches[1];
        alert(id);
    }
</script>
Copy after login

Recommended learning: javascript video tutorial

The above is the detailed content of How to get the current method name in javascript. For more information, please follow other related articles on the PHP Chinese website!

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