2012年1月17日火曜日

JavaScript Class template for C# users (or others)

compared with

http://www.atmarkit.co.jp/fdotnet/basics/oop02/oop02_01.html



    var Class1 = function(_p)
    {
        this.init(_p);
    };
   
    Class1.prototype = //prototype of an Object
    {
        value1: "some value",   // public Property

        init: function(_p)    // Constructor
        {
            alert(_p);
        },

        cal: function(x)           //public Method
        {
            var _a = 10;            //private Value

            var _cal = function(_x) //private Method
            {
                return _a + _x;
            }

            return _cal(x);
        }

    };

    var obj1 = new Class1("test");

    alert(obj1.cal(3));