JScript.NET private variables

Posted by Paul Podlipensky on Stack Overflow See other posts from Stack Overflow or by Paul Podlipensky
Published on 2010-01-23T20:53:21Z Indexed on 2010/03/13 17:05 UTC
Read the original article Hit count: 651

I'm wondering about JScript.NET private variables. Please take a look on the following code:

import System;
import System.Windows.Forms;
import System.Drawing;

var jsPDF = function(){
 var state = 0;

 var beginPage = function(){
  state = 2;
  out('beginPage');
 }

 var out = function(text){
  if(state == 2){   
   var st = 3;
  }
  MessageBox.Show(text + ' ' + state);
 }

 var addHeader = function(){
  out('header');
 }  

 return {
  endDocument: function(){
   state = 1;
   addHeader();
   out('endDocument');
  },

  beginDocument: function(){
   beginPage();
  }
 }
}

var j = new jsPDF();

j.beginDocument();
j.endDocument();

Output:

beginPage 2
header 2
endDocument 2

if I run the same script in any browser, the output is:

beginPage 2
header 1
endDocument 1

Why it is so??

Thanks, Paul.

© Stack Overflow or respective owner

Related posts about jscript.net

Related posts about private