Newbie question on scope and construtor

Thursday, October 10, 2013


I've got a JS function used as a constructor. The HTML file includes code to 'new' the constructor to create the object.

My understanding is that variables defined within the constructor should have the context of the constructor and not of 'window'. But in my case what I'm seeing is that within a declared function in the constructor, the context is 'window':

function MyCtor()
    var a;
    var b;

    var myFunc = function() {
         debugger; //#2
         // code for function

// more code

    debugger;  //#1
    debugger; //#3

} //end MyCtor

When execution breaks at debugger #1, 'this' refers to 'MyCtor'. However, at debugger #2 this refers to 'window'. And at debugger #3 it is 'MyCtor'.

What happened to the MyCtor context within myFunc? Clearly I'm missing something basic here.



You received this message because you are subscribed to the Google Groups "JavaScript Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
For more options, visit


Post a Comment

Note: Only a member of this blog may post a comment.

Copyright © 2010 Web Design | Free Blogger Templates by Splashy Templates | Layout by Atomic Website Templates

Vida de bombeiro Recipes Informatica Humor Jokes Mensagens Curiosity Saude Video Games Animals Diario das Mensagens Eletronica Rei Jesus News Noticias da TV Artesanato Esportes Noticias Atuais Games Pets Career Religion Recreation Business Education Autos Academics Style Television Programming Motosport Humor News The Games Home Downs World News Internet Design Entertaimment Celebrities 1001 Games Doctor Pets Net Downs World Enter Jesus Mensagensr Android Rub Letras Dialogue cosmetics Genexus lasofia thebushrajr wingshock tripedes gorduravegetal dainfamia dejavu-transpersonal jsbenfica republicadasbadanas ruiherbon iranianforaryans eaystcheyl fotosdanadir Só Humor Curiosity Gifs Medical Female American Health Madeira Designer PPS Divertidas Estate Travel Estate Writing Computer Matilde Ocultos Matilde futebolcomnoticias girassol lettheworldturn topdigitalnet Bem amado enjohnny produceideas foodasticos cronicasdoimaginario downloadsdegraca compactandoletras newcuriosidades blogdoarmario arrozinhoii