peterS.: *private static* durch umschliessende anonyme *function stacks*

Beitrag lesen

gruss Struppi, hallo felix12,

...
Was du willst ist eine private statische Variabel, ich weiß nicht,
ob es sowas in Java gibt, in JS kann man sowas konstruieren.

... Du willst Zugriff auf ein statische private Variabel über eine
statische Funktion, richtig?

Also:

(function() {

var privat = 'hallo';
window.SomeClass = function (){}
SomeClass.hallo = function() { return privat; };
})();

  
wobei ich auch aus aesthetisch gruenden den zur \*klasse\* hin- oder  
besser zum \*private static\* wrapper umgebogenen anonymen funktions-  
stack zusammen mit dem konstruktor so abhandeln wuerde, dass es nicht  
mehr noetig ist, diesen (den konstruktor) ueber [window] zu adressieren:  
  
  
~~~javascript
var SomeConstructor = (function () { // kind of *private static* wrapper function  
  
  var hallo = "hallo";  
  
  var cnstr = (function () {/*  
  
    code */  
  
  });  
  cnstr.getHallo = (function () {  
  
    return hallo;  
  });  
  
  return cnstr;  
  
})();  
  
var obj = new SomeConstructor();  
alert(obj.hallo); // [undefined]  
alert(obj.getHallo); // [undefined]  
alert(SomeConstructor.getHallo()); // "hallo"  
/*  
  copy und paste nach : [[link:http://jconsole.com/]]  
*/

@ alle:

gaebe es darueber hinaus noch eine allgemeine unterstuetzung von
[__defineSetter__] bzw. [__defineGetter__], waere es ein leichtes,
auch noch konstanten, wie z.b. bei [Math] existierend, umzusetzen:

var OtherConstructor = (function () { // kind of *private static* wrapper function  
  
  var hallo = "hallo";  
  
  var cnstr = (function () {/*  
  
    code */  
  });  
  cnstr.__defineGetter__("HALLO", (function () { // gecko only  
  
    return hallo;  
  }));  
  
  return cnstr;  
  
})();  
  
var obj = new OtherConstructor();  
alert(obj.hallo); // [undefined]  
alert(obj.HALLO); // [undefined]  
alert(OtherConstructor.HALLO); // "hallo"  
/*  
  copy und paste nach : [[link:http://jconsole.com/]]  
*/

so long - peterS. - pseliger@gmx.net

--
»Because objects in JavaScript are so flexible, you will want to think differently about class hierarchies.
Deep hierarchies are inappropriate. Shallow hierarchies are efficient and expressive.« - Douglas Crockford
ie:( fl:) br:> va:( ls:& fo:) rl:) n3;} n4:} ss:} de:µ js:} mo:? zu:]
0 45

Interne public static member nicht aufrufbar

felix12
  • javascript
  1. 0
    Cheatah
    1. 0
      felix12
      1. 0
        Cheatah
        1. 0
          felix12
          1. 0
            MudGuard
            1. 0
              felix12
              1. 0
                Struppi
                1. 0
                  Patrick Andrieu
                  1. 1
                    peterS.
                    1. 0
                      Patrick Andrieu
                    2. 0
                      felix12
                2. 1

                  *private static* durch umschliessende anonyme *function stacks*

                  peterS.
                  1. 0
                    felix12
                    1. 0
                      Struppi
                      1. 0
                        felix12
                        1. 2

                          klassenlose vollwertige und flexible oo auf funktionaler basis

                          peterS.
                          1. 0
                            felix12
                            1. 0
                              felix 12
                            2. 0
                              Struppi
                              1. 0
                                felix12
                            3. 1

                              vererbung / delegationsprinzipien

                              peterS.
                              1. 0
                                felixcat
                                1. 1

                                  »[Function].arguments.callee« versus »arguments.callee«

                                  peterS.
                                  1. 0
                                    felix12
      2. 0
        Kai345
        1. 0
          felix12
          1. 0
            ChrisB
            1. 0
              felix12
              1. 0
                Struppi
                1. 0
                  felix12
                  1. 0
                    Struppi
                    1. 0
                      felix12
                      1. 0
                        Struppi
                      2. 1

                        einfache objekte/namensraeume und singleton-konstrukte

                        peterS.
                        1. 0
                          Struppi
              2. 2
                Timo "God's Boss" Reitz
                1. 0
                  felix12
                  1. 0
                    Kai345
                    1. 0
                      felix12
                      1. 0
                        Kai345
                        1. 0
                          Kai345
                          1. 0
                            felix12
                            1. 0
                              Kai345
  2. 4
    molily