/    Sign up×
Community /Pin to ProfileBookmark

HELP please! problem with functions

Ok, i’m having a very annoying problem and would appreciate any help.

I’m not sure how to word this, so take a look at EXAMPLE 1, which works, and EXAMPLE 2, which doesn’t work. I don’t understand whey EXAMPLE 2 doesn’t work, and I need it to.

[quote]

/*********
EXAMPLE 1
*
**
******/
function test()
{
this.temp
}

function go(obj)
{
alert(obj.temp)
}

UglySquirrel = new test()
UglySquirrel.temp=1

go(UglySquirrel) //alerts “1”

[/quote]

[quote]

/*********
EXAMPLE 2
*
**
******/
function test_1()
{
this.temp
}

function test_2()
{
this.testFunction=new Array()
}

go= new test_2()
go.testFunction[0]=new function(obj)
{
alert(obj.temp)
}

UglySquirrel = new test_1()
UglySquirrel.temp=1

go.testFunction[0](UglySquirrel)

[/quote]

It seems that when i declare a function inside of an array, it tries to run the function instead of just storing it for later use. And obviously running the function fails because obj.temp has no value at that point. What can I do to fix this? Any insight into the error of my ways is welcome ?

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Jan 17.2007 — drop the [I]new[/I] on [I]new function(obj)[/I]

Eric
Copy linkTweet thisAlerts:
@mishkinauthorJan 17.2007 — LOL. well that worked. thanks. ?
Copy linkTweet thisAlerts:
@mrhooJan 17.2007 — Moderator- please remove this post, thanks. Excuse me, guys.
Copy linkTweet thisAlerts:
@mishkinauthorJan 17.2007 — just out of curiosity, why on earth would you want this post removed?
Copy linkTweet thisAlerts:
@NXorableWandrerJan 17.2007 — just out of curiosity, why on earth would you want this post removed?[/QUOTE]

Hahaha. I wasn't here earlier to see, but I would guess that he posted something silly himself and edited it away. I don't think he's talking about the entire thread.
Copy linkTweet thisAlerts:
@mrhooJan 17.2007 — !'ll tell you. I posted my solution and saw that it was almost verbatum a duplicate of a post that hit the thread just before I sent mine.

Ordinarily I wouldn't care, but not 5 minutes before, the same thing happened- I sent a a clone of the previous post.

And the author of both posts was Alien51- I better get out my aluminum foil hat.
Copy linkTweet thisAlerts:
@A1ien51Jan 17.2007 — mrhoo,

You better learn how to read and type faster! I could be faster if there was no that 60 second limit!

Eric
×

Success!

Help @mishkin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...