Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : can.Construct and private fucntions and variable

$
0
0
You can set up "private" items (context variables available to some public interface) in the construct's init() method.

  1. > can.Construct.extend("Bar", { init : function() { var b = 0; this.binc = function(){ return ++b; }; } });
    function Constructor() { // All construction is actually done in the init method. if (!initializing) { return this.constructor !== Constructor && // We are being called without `new` or we are extending. arguments.length && Constructor.constructorExtends ? Constructor.extend.apply(Constructor, arguments) : // We are being called with `new`. Constructor.newInstance.apply(Constructor, arguments); } } dashboard.js:13297
    > b = new Bar();
    Constructor {bincfunctioninitfunctionconstructorfunctionsetupfunctionproxyfunction}
    > b.binc()
    1
    > b.binc()
    2
    > b.binc()
    3
    > c = new Bar()
    Constructor {bincfunctioninitfunctionconstructorfunctionsetupfunctionproxyfunction}
    > c.binc()
    1
    > c.binc()
    2
    > b.binc()
    4


Viewing all articles
Browse latest Browse all 3491

Trending Articles