How to check if the same function name is already used in javascript

Discussion in 'Javascript' started by Wootaek Choi, Aug 18, 2003.

  1. Wootaek Choi

    Wootaek Choi Guest

    Hi, everybody..

    I try to make common debug function
    that call in every js files used in a HTML..

    but if same debug function name is defined in.... more than two javascrpt files,
    it would cause trouble.

    so, I want to check if the function name is used at first,
    and then define debug function.
    Is the anyway for this?
    Wootaek Choi, Aug 18, 2003
    1. Advertisements

  2. Wootaek Choi

    Fox Guest

    // whatever your code is...
    Fox, Aug 18, 2003
    1. Advertisements

  3. Wootaek Choi

    Andy Fish Guest

    I don't think it would actually cause any harm if you defined the function
    twice. In javascript that's just like assigning a variable the same value it
    already has.

    as a matter of good practice I would use fox's suggestion though
    Andy Fish, Aug 18, 2003
  4. if the browser follows the ECMA specification, then that function is
    not a function declaration, but a function expression. The name is then
    only visible inside the function.

    A lot of browsers don't, but that's not an excuse :)

    This will be safer:
    if (!debug) {
    var debug = function() {
    Lasse Reichstein Nielsen, Aug 18, 2003
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.