Click here to Skip to main content
15,886,071 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: simple javascrpt: checkbox Pin
AndyInUK5-Sep-11 5:43
AndyInUK5-Sep-11 5:43 
GeneralRe: simple javascrpt: checkbox Pin
Evan Gallup5-Sep-11 6:53
Evan Gallup5-Sep-11 6:53 
QuestionXML and Javascript Pin
Member 820418431-Aug-11 19:26
Member 820418431-Aug-11 19:26 
QuestionRe: XML and Javascript Pin
DaveAuld31-Aug-11 22:43
professionalDaveAuld31-Aug-11 22:43 
AnswerRe: XML and Javascript Pin
Evan Gallup3-Sep-11 19:39
Evan Gallup3-Sep-11 19:39 
Questioniphone style switch Pin
AndyInUK30-Aug-11 23:07
AndyInUK30-Aug-11 23:07 
AnswerRe: iphone style switch Pin
AndyInUK2-Sep-11 1:06
AndyInUK2-Sep-11 1:06 
QuestionJavaScript class problem [modified] Pin
Wjousts25-Aug-11 6:09
Wjousts25-Aug-11 6:09 
I'm not a habitual user of JavaScript, but I have a particular need for it right now, so maybe my problem is due to some fundamental misunderstanding of how JavaScript is supposed to work and my expectation that it'll work somewhat like the C# I'm familiar with. Anyway, I have a class (or object prototype or whatever the correct term in JavaScript is supposed to be) that looks something like this:

JavaScript
function MyClass() {

    //....

    this.OnTimerStart = function() {
        // Do some stuff
    };

    MyClass.prototype.StartTimer = function() {
        if (this.OnTimerStart != null) {
            this.OnTimerStart();
        }
    }
}


Now when I use it, I create an object like so:

JavaScript
var myObj = new MyClass();


Now here's my problem, in the StartTimer function this.OnTimerStart returns undefined (so the != null comparison is always false and the function doesn't get called), but myObj.OnTimerStart is defined and can be executed (directly running myObj.OnTimerStart() works). So why doesn't the prototype method StartTimer seem to know what "this" is? At least in the case when a variable is a function (it doesn't seem to have a problem when a variable is just a string or an int for example). What am I not understanding here?
(Note: tested in IE8, I have other problems with Firefox at the moment which may or may not be related)

Edit: fixed typo in StartTimer

modified on Thursday, August 25, 2011 1:40 PM

AnswerRe: JavaScript class problem Pin
Graham Breach25-Aug-11 6:34
Graham Breach25-Aug-11 6:34 
GeneralRe: JavaScript class problem Pin
Wjousts25-Aug-11 7:40
Wjousts25-Aug-11 7:40 
AnswerRe: JavaScript class problem Pin
AspDotNetDev25-Aug-11 7:45
protectorAspDotNetDev25-Aug-11 7:45 
GeneralRe: JavaScript class problem Pin
Wjousts25-Aug-11 8:06
Wjousts25-Aug-11 8:06 
GeneralRe: JavaScript class problem Pin
AspDotNetDev25-Aug-11 8:11
protectorAspDotNetDev25-Aug-11 8:11 
GeneralRe: JavaScript class problem Pin
Wjousts25-Aug-11 8:18
Wjousts25-Aug-11 8:18 
AnswerRe: JavaScript class problem Pin
AspDotNetDev25-Aug-11 7:19
protectorAspDotNetDev25-Aug-11 7:19 
GeneralRe: JavaScript class problem Pin
Wjousts25-Aug-11 7:43
Wjousts25-Aug-11 7:43 
AnswerRe: JavaScript class problem Pin
AspDotNetDev25-Aug-11 7:47
protectorAspDotNetDev25-Aug-11 7:47 
GeneralRe: JavaScript class problem Pin
Wjousts25-Aug-11 7:58
Wjousts25-Aug-11 7:58 
Questionjquery dialog autosize [modified] Pin
fififlowertot24-Aug-11 3:05
fififlowertot24-Aug-11 3:05 
AnswerRe: jquery dialog autosize Pin
Gerben Jongerius24-Aug-11 19:50
Gerben Jongerius24-Aug-11 19:50 
QuestionPassing on Javascript array data to a PHP-array Pin
Gert Koetsier18-Aug-11 6:19
Gert Koetsier18-Aug-11 6:19 
AnswerRe: Passing on Javascript array data to a PHP-array Pin
Evan Gallup3-Sep-11 18:49
Evan Gallup3-Sep-11 18:49 
QuestionJavascript data (array) pass on to PHP Pin
Gert Koetsier18-Aug-11 6:15
Gert Koetsier18-Aug-11 6:15 
Questiondynamic progress bar with respect to time Pin
amjadali25516-Aug-11 18:27
amjadali25516-Aug-11 18:27 
AnswerRe: dynamic progress bar with respect to time Pin
Richard MacCutchan16-Aug-11 22:39
mveRichard MacCutchan16-Aug-11 22:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.