|
Nested method Calling outside
Hi All,
I am trying to call method "childMethod" which is a private method and is not available outside the testSingleton object. i tried couple of ways to achieve this but have found the right solution to it. so would be helpful if someone can point me or tell me the right approach to it.
May be i havn't defined the method perfectly..
Below is the code for your rerefrence..
Thanks in Advance,
Tricker
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="JavaScript" src="jquery.js" type="text/javascript"></script>
<script type="text/javascript">
var testSingleton = {
init: function(){
testSingleton.myFirstMethod();
testSingleton.siblingToInit();
},//init ends here
myFirstMethod:function(){
function childMethod(){
alert('i am a ChildMethod of init');
}//childMethod ends here
},//myFirstMethod ends here
siblingToInit: function(){
alert('i am sibling of init');
}//siblingToInit ends here
}//testSingleton ends here
$(document).ready(function(){
testSingleton.init();
});
</script>
</head>
<body>
<script type="text/javascript">
testSingleton.myFirstMethod.childMethod();
</script>
</body>
</html>
|