ska: unmasked interrupts
Tuesday, 10. February 2009

Still not enough pages about javascript objects and closures

Blogposting about javascript tricks seems quite fashionable. Now more than ever.

But there are a lot of old and outdated models concerning javascript objects, closures and the distinction between private, privileged and private static attributes.

Here's my clean and easy example.

var myObject = (function () {
  // private static, objectIdPool to keep an index
  // on all objects created
  var objectIdPool =0;
  return (function ( val ) {
			
    // private
    var myPrivate ;
    var myId;
			
    // privileged
    this.getPrivate = function () {
      alert ("object # " + myId + " private : " + myPrivate)
    };
    this.setPrivate = function ( val ) {
      myPrivate = val;
    };

    // execute at construction
    myId = objectIdPool++;
    myPrivate = val;
    alert (myId + ":" + myPrivate);
    });
} )(); // inline execution

var dummy0 = new myObject ("abc");
dummy0.getPrivate();  // returns abc from #0

var dummy1 = new myObject ("123");
dummy1.getPrivate();  // returns 123 for #1
dummy0.getPrivate();  // returns abc for #0

dummy1.setPrivate ("def");
dummy1.getPrivate(); // returns def for #1
dummy0.getPrivate(); // returns abc for #0

Another fine contribution to make google a better place.

... read more stories on the topic int

... permalink... comment  ...xml version of this page

Online for 924 days
Last update: 2010.09.01, 12:35
... home
... about
... news feeds
search
 
status
You're not logged in ... login
tweets
unmasked links of interest
Anonymous Pro
Anonymous Pro (2009) is a family of four fixed-width fonts designed especially with...
Lawsuit: Disney, others spy...
Ars Technica: A flash based tracking cookie resists deletion and is aimed on kids...
Mana Bar :: Australia's First...
Australias first video game bar - Princess Peach never before looked that tempting
You're Doing It Wrong - ACM...
You're Doing It Wrong Think you've mastered the art of server performance?...
Facebook's Eroding Privacy...
To help illustrate Facebook's shift away from privacy, the Electronic Frontier...
Amazon.com: Contech Electronics...
When you listed your product on Amazon, be aware of user generated content, especially...
Improving download behaviors...
The confusing and inconsistent state of downloading files using a web browser has...
Employers: Look to gaming...
Clearly defined goals and fair, incremental rewards are two game design techniques...
Edge 313
David Gelernter: Time to start taking the internet seriously
Linguistic profiling: The...
Speakers with German accents ? even if they stumble into grammatical errors ? are...
more unmasked links...
unmasked recent updates
Nice
As I can see, my recommendation concerning ImgPro is...
by nie (2010.09.01, 12:35)
Intermedia Fotoficient...
A few things happened backstage, that involved releasing...
by ska (2010.08.31, 13:40)
...
Et voila.
by ska (2010.08.30, 17:24)
Flexible layouts
by ska (2010.08.27, 13:33)
Intermedia Fotoficient...
And while we're on it, we provided a functional facelift...
by ska (2010.08.26, 16:38)
menu
... home
... topics
... galleries

... Pixelbloxx home
calendar
February 2009
Mon
Tue
Wed
Thu
Fri
Sat
Sun
 
 
 
 
 
 
 1 
 2 
 3 
 4 
 5 
 6 
 7 
 8 
 9 
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 
 

xml version of this page

made with antville

XING