Add properties to function while in function with out specifying function ?

Discussion in 'Javascript' started by Richard A. DeVenezia, Sep 5, 2003.

  1. I can add a property to a function while in the function

    function foo () {
    foo.X=1;
    }
    alert (foo.X) // undef
    foo()
    alert (foo.X) //1

    or

    function foo (name,value) {
    foo [name] = value
    }
    foo ('A',1)
    alert (foo.A) // 1

    how would I add a property to currently running function without naming the
    function ?

    self doesn't work
    function foo (name,value) {
    self [name] = value
    }
    foo ('A',1)
    alert (foo.A)
    alert (self['A'])



    function foo ( name, value ) {
    **something** [name] = value
    }
    foo ('X',9)
    alert (foo.X) // want 9

    What would **something** be ?

    --
    Richard A. DeVenezia
     
    Richard A. DeVenezia, Sep 5, 2003
    #1
    1. Advertising

  2. "Richard A. DeVenezia" <> schreef in bericht
    news:bja11p$h0bgl$-berlin.de...
    >
    > function foo ( name, value ) {
    > **something** [name] = value
    > }
    > foo ('X',9)
    > alert (foo.X) // want 9
    >
    > What would **something** be ?


    function foo ( name, value ) {
    foo[name] = value
    }


    JW
     
    Janwillem Borleffs, Sep 5, 2003
    #2
    1. Advertising

  3. > I can add a property to a function while in the function
    >
    > function foo() {
    > foo.X = 1;
    > }


    Ideally yes, but IE has a bug which frustrates that pattern, requiring instead

    foo = function () {
    foo.X = 1;
    };

    http://www.crockford.com/javascript/remedial.html
     
    Douglas Crockford, Sep 5, 2003
    #3
  4. "Janwillem Borleffs" <> wrote in message
    news:3f588969$0$28902$...
    >
    > "Richard A. DeVenezia" <> schreef in bericht
    > news:bja11p$h0bgl$-berlin.de...
    > >
    > > function foo ( name, value ) {
    > > **something** [name] = value
    > > }
    > > foo ('X',9)
    > > alert (foo.X) // want 9
    > >
    > > What would **something** be ?

    >
    > function foo ( name, value ) {
    > foo[name] = value
    > }
    >
    >
    > JW
    >
    >



    I found what I was looking for.

    function foo (name,value) {
    var callee = arguments.callee
    callee[name] = value
    }
    foo ('X', 9)
    alert (foo.X)

    presumed to be the same as

    > function foo ( name, value ) {
    > foo[name] = value
    > }


    but not needing to know the function name at source writing time.

    --
    Richard A. DeVenezia
     
    Richard A. DeVenezia, Sep 5, 2003
    #4
  5. "Douglas Crockford" <> writes:

    > Ideally yes, but IE has a bug which frustrates that pattern,
    > requiring instead


    Which version of IE is that, and what is the bug?
    It would sound like it prevents function declarations from declaring
    recursive functions.

    /L
    --
    Lasse Reichstein Nielsen -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Sep 5, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nathan Sokalski
    Replies:
    2
    Views:
    491
    =?Utf-8?B?R2FyeSBL?=
    Jun 15, 2005
  2. Praveen Ramesh

    Specifying dynamic default values for properties in custom controls:

    Praveen Ramesh, Sep 2, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    137
    Praveen Ramesh
    Sep 2, 2004
  3. Nathan Sokalski

    Specifying Width and Height properties as percentages

    Nathan Sokalski, Jun 13, 2005, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    136
    Gary K
    Jun 15, 2005
  4. Nathan Sokalski

    Specifying Width and Height properties as percentages

    Nathan Sokalski, Jun 13, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    132
    Gary K
    Jun 15, 2005
  5. Ronald Fischer
    Replies:
    2
    Views:
    233
    Scott Miller
    May 16, 2007
Loading...

Share This Page