Wednesday 15 September 2010

Calling private functions nested in a var Javascript -


I want to rewrite a file to include public and private wars. I'm trying to do something like this:

  var personalfuck = (function () {// private work var _iAmPrivate = function (param, args) {// code} var _soAmI = function Ultimate) {// code} Returns Pivot Function;}) (); Var PubObj = {someVar: 1, getPrivFunc: PrivateFunc, publicFunc: Function (Ultimate) {// This does not work. GetPrivFunc._iAmPrivate (Some, Ultimate); // It does not get either PrivFunc._soAmI (Ultimate); }}; I have an " getPrivFunc  is undefined" error. I think that  getPrivFunc  is outside of  PubObj  Was running, but I ran into the same problem. Calling  PrivateFunc  also give errors. I think it's a stupid error, I'm not seeing it.  

Perhaps there is a better way to do this? Any thing declared with

var will reach out to that announced function Can not go. You can do something like this instead, the important thing to keep in mind is that where is your var , defines the scope of their declaration.

  var PubObj; (Function () {PubObj = {someVar: 1, publicFunc: function (param) {_iAmPrivate (this.somevar, param); _soAmI (param);}} // inner functions var _iAmPrivate = function (param, args) { // code}; var _soAmI = function (absolute) {// code};}) ();    

No comments:

Post a Comment