accessing method skillet.toString() in javascript -
(function( skillet, $, undefined ) { //private property var ishot = true; //public property skillet.ingredient = "bacon strips"; //public method skillet.fry = function() { var oliveoil; additem( "\t\n butter \n\t" ); additem( oliveoil ); console.log( "frying " + skillet.ingredient ); }; //private method function additem( item ) { if ( item !== undefined ) { console.log( "adding " + $.trim(item) ); } } }( window.skillet = window.skillet || {}, jquery )); //adding new functionality skillet (function( skillet, $, undefined ) { //private property var amountofgrease = "1 cup"; //public method skillet.tostring = function() { console.log( skillet.quantity + " " + skillet.ingredient + " & " + amountofgrease + " of grease" ); console.log( ishot ? "hot" : "cold" ); }; }( window.skillet = window.skillet || {}, jquery ));
for js code
i can access skillet.fry();
adding butter frying bacon strips
but not skillet.tostring();
it return
"[object object]"
is there way can access private members
such oliveoil or ishot ?
you have make ishot , oliveoil public properties of skillet, or else cannot reach them.
i change:
var ishot = true;
to:
this.ishot = true;
change:
var oliveoil;
to:
this.oliveoil = null;
and acces them outside skillet function either window.skillet.ishot | window.skillet.fry.oliveoil or skillet().ishot | skillet().fry.oliveoil.
i'm not 100% sure on of last stuff, should work, in theory. hey, tried.
Comments
Post a Comment