Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 28th, 2003, 04:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Moharo
Default OOP with JavaScript

consider the following:

function dMenu(title)
{
    this.time = 0;
    this.items = null;
    this.header = null;
    this.title = title;
}

dMenu.prototype.startIt = function()
{
     this.time++;
     setTimeout( ??????, 1000 );
}

what should i type instead of question marks to increment "time" variable every 1 second?

the genuine genius
__________________
www.campusgrind.com - college portal
 
Old September 28th, 2003, 06:05 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Presumably it would have to call itself therefore it would be easier if it were not an anonymous function:
Code:
dMenu.prototype.startIt = incTime;

function incTime()
{
   this.time++;
   setTimeout( incTime, 1000 );
}

--

Joe
 
Old September 29th, 2003, 09:13 AM
Registered User
 
Join Date: Sep 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

try arguments.callee to obtain a reference of the Function object beeing executed. This way your func can stay anonymous.
 
Old September 29th, 2003, 10:14 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I thought this was "caller" and a property of the Function object? In which case you're no better off.

--

Joe





Similar Threads
Thread Thread Starter Forum Replies Last Post
OOP Design Prob SiliconFuRy Java Basics 1 April 6th, 2006 03:01 PM
Classes (OOP) in VBScript 6 benr Pro VB 6 12 March 13th, 2006 04:02 PM
OOP design raj_sekhar C++ Programming 1 August 23rd, 2005 11:44 AM
passing a php oop object in a form buckarette Pro PHP 2 December 24th, 2003 07:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.