List of global user defined functions in JavaScript?

后端 未结 3 1980
南方客
南方客 2020-11-30 06:28

Is it possible to get a list of the user defined functions in JavaScript?

I\'m currently using this, but it returns functions which aren\'t user defined:

<         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 06:58

    Using Internet Explorer:

    var objs = [];
    var thing = {
      makeGreeting: function(text) {
        return 'Hello ' + text + '!';
      }
    }
    
    for (var obj in window){window.hasOwnProperty(obj) && typeof window[obj] === 'function')objs.push(obj)};
    

    Fails to report 'thing'.

提交回复
热议问题