Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8543693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:22:02+00:00 2026-06-11T12:22:02+00:00

A script was needed to quickly tell me how many html comments there are

  • 0

A script was needed to quickly tell me how many html comments there are on the page and what their contents are. Using an anonymous function for recursive DOM traversal seemed appropriate:

var comments = []; //set up an array where comment contents will be copied to

(function(D) {
  if (8===D.nodeType) comments.push(D.nodeValue); //check if node is a comment
  D=D.firstChild;
  while (D) {
    arguments.callee(D); //recursively look for comments...
    D=D.nextSibling; //...and remember to iterate over all children of any node
  }
})(document);

console.log(comments.join("\r\n")); //list all comments

Fiddle works as expected, but I was curious if it was really the same function called over and over, or were there multiple references to the original function called, or were there multiple identical functions called… After all, there has been no named reference made, so how would it work as the traversal goes deeper? I thought I may be able to check that by adding the following code into while (D) {...}

//tmpCallee has been declared
if (tmpCallee) {
  console.warn(arguments.callee === tmpCallee);//true
  /*great, means these should be both pointing to the same function*/
  console.log(arguments.callee === arguments.caller);//false
  /*wait, what? didn't we just establish above that 
    all of our functions called recursively would be the same?*/
  console.log(arguments.caller);//undefined... but it was called recursively!
  console.log(arguments.callee);//prints our function code verbatim as it should
}
tmpCallee = arguments.callee;

I’m confused. 1) am I really calling the same function over and over or are there multiple identical functions called or is something else at play? 2) why does arguments.caller not point at our function? it was clearly invoked by it – that’s how recursion works, no?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:22:04+00:00Added an answer on June 11, 2026 at 12:22 pm

    am I really calling the same function over and over or are there multiple identical functions called or is something else at play?

    Yes, you have only one function instance, which you refer to all the time. However, you are setting up a call stack in which local variables (in your case the argument D) would be saved for every invocation.

    why does arguments.caller not point at our function?

    There is no caller property on the arguments object, it was removed. You probably meant the caller property of the function object, which is non-standard but still usable (although forbidden in strict mode as well as argments.callee).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could anyone tell me why 'function()' right after .ready is needed to make the
I am using __autoload in my script to include classes as needed. My script
I needed to write a script to enter multi-line input to a program (
I want to build a script that builds up the data needed for the
First steps in FreeBSD: trying to run my installation script. Fast help needed: #
Script link on master page: <head runat=server> <script src=<%=ConfigurationManager.AppSettings[ApplicationURL].ToString()%>Scripts/jquery-1.7.2.js type=text/javascript language=javascript></script> </head> Default.aspx page
PHP script to read in user action requests and parse them to their components.
aspx script: <script type=text/javascript> $(document).ready(function() { $(.div_soru).hide(); $(.div_soru).first().show(); $(.onceki).click(function() { if ($(this).closest(.div_soru).prev(.div_soru).html() != null)
I needed to work with Facebook SDK, so with some help, I wrote script
I'm currently teaching an employee ECMA script as it is needed in maintaining a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.