Create Class in Javascript example

taken right from here (a hebrew blog, no. 2 in list)
http://www.softwarearchiblog.com/2012/07/jquery-c-java.html

var myNS = myNS || {}; // ns is optional o.c.
myNS.Calculator = function () {
  // private members
  var value = 0;

  var addBy = function (x) {
    value += x;
    console.log(
'value = ' + value);
  };
  var multiplyBy = function (x) {
    value *= x;
    console.log(
'value = ' + value);
  };

  
return { // public parts (aka interface)
    addBy: addBy,
    multiplyBy: multiplyBy
  };
};
var calc = new myNS.Calculator();
calc.addBy(4);
calc.multiplyBy(6);
// 24

Comments

Popular posts from this blog

OverTheWire[.com] Natas Walkthrough - JUST HINT, NO SPOILERS

Asp.Net Ending Response options, Response.End() vs CompleteRequest()

SOLVED The item could not be indexed successfully because the item failed in the indexing subsystem