Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call a function inside a class

Status
Not open for further replies.

rob51383

Programmer
Jun 23, 2004
134
US
this is what I got:

Code:
var House = {

	obj : null,

	init : function()
	{
		// do something
	},

	build : function()
	{
		function onestory()
		{
		//do something
		}

		function twostory()
		{
		//do somthing
		}
	}
};

House.init();

What I want to be able to do is call "House.build.twostory()" but I keep getting "House.build.twostory() is not a function".

Does anyone know how I would extend the build method so I can make direct calls to functions within it, not executing the rest of the code? When I call House.build() and have the code for "onestory" outside a function it works fine, just cant figure out how to code it so I can make th direct call to the function inside without passing a "House.build(onestory)" and doing an if/elseif system.

Thanks
 
Try this instead:

Code:
<html>
	<head>
	<script type="text/javascript">
	<!--

		function Build() {
		}
		Build.prototype.onestory = function() {
			alert('build.onestory');
		}

		Build.prototype.twostory = function() {
			alert('build.twostory');
		}

		function House() {
			this.obj = null;
			this.build = new Build();
		}
		House.prototype.init = function() {
			alert('house.init');
		}


		var myHouse = new House();
		myHouse.init();
		myHouse.build.onestory();
		myHouse.build.twostory();

	//-->
	</script>
</head>
<body></body>
</html>

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top