codicille / edsa

Web-based and multi-devices e-book reader.
Other
7 stars 0 forks source link

Classes, scopes & objects #10

Closed EtienneLem closed 11 years ago

EtienneLem commented 11 years ago

To whom it may concern (most likely @j15e, @renaudleo)

Class skeleton:

var ClassName = function() { this.initialize.apply(this, arguments) };
ClassName.prototype = (function() { var pro = {};

  // Public scope --------------------------------------------------------------
  pro.initialize = function(args) {
    // Constructor
  }

  pro.publicFunction = function() {
    // ...
  }

  // Private scope -------------------------------------------------------------
  var privateFunction = function() {
    // ...
  }

return pro })();

// OOP
// className = new ClassName();
// className.publicFunction();

// More of a Singleton fan? Why sure!
// window.ClassName = new ClassName();
// ClassName.publicFunction();

ClassName.prototype only returns an object of public functions. Yay encapsulation!

Why pro you ask? So that public and private functions are aligned :dancers:

Open to comments/suggestions in French, English or Spanish… whatever floats your boat.

renaudleo commented 11 years ago

Holla! Works perfectly for me. La nécessité du pro sera peut-être pas tout à fait claire pour quelqu'un qui débarque là-dedans éventuellement, mais en même temps c'est pas un gros bâton dans les roues. I'm confortable with it.