oop - private method in an javascript object -
i've object looks this:
var obj ={ property : '', myfunction1 : function(parameter){ //do stuff here } }
i need set private properties , functions, can not accessed/seen outside of object. not working var property:,
or var myfunction1
next question is, if phone call function within or outside object, have obj.myfunction()
. asign "this" variable. self : this
. , phone call within object functions , variables self.property
, self.myfunction
.
how? :)
there many ways this. in short: if dou define function within function, inner function private, long not provide reference if.
(function obj(){ var privatemethod = function() {}; var publicmethod = function() { privatemethod(); ... }; homecoming { pubmethod: publicmethod } }());
javascript oop object private
No comments:
Post a Comment