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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is there a way to use prototypes

Status
Not open for further replies.

skiflyer

Programmer
Sep 24, 2002
2,213
0
0
US
Is prototyping supported by javascript, and if so what's the syntax?

I.e. if function a calls function b, but function a is above function b, can I somehow define function b such that function a is able to call it?

-Rob
 
I'm puzzled. What is the connection between prototyping and calling one function from another function?

Code:
<html>
<head>
	<title>A Will Be Calling B</title>
	<script>
	var x = &quot;&quot;;
	var y = &quot;Inside B&quot;;
	var z = &quot;&quot;;
	
	a();
	
	function a(){
		x = &quot;Inside A&quot;;
		z = b();
	}
	
	function b(){
		return y;
	}
	
	</script>
</head>

<body>

<h3>Call Me Call You</h3>
<script>
document.write( &quot;<br>x: &quot; + x );
document.write( &quot;<br>y: &quot; + y );
document.write( &quot;<br>z: &quot; + z );
</script>

</body>
</html>

As I understand it Javascript does support prototyping which is similar to instantiation I think.

Code:
var x = &quot;&quot;;
var y = &quot;Inside B&quot;;
var z = &quot;&quot;;

var u = new c();
x = u.x_like;
z = u.b_work();

function b(){
   return y;
}

function c(){
  this.b_work = b;
  this.x_like = &quot;Inside C&quot;;
}
 
hie

function a.. function b.. above.. below..

well.. js has a THING called a PROTOTYPE

may be this is what skiflyer is lookin for..

try
~~~~~~~~~~~~~~~~~
String.prototype.allo=function(arg)
{
alert(arg)
}
var a = &quot;aaa&quot;
a.allo(&quot;bbb&quot;)
~~~~~~~~~~~~~~~~~

 
No, he knew what I was looking for... but he's saying it's just not necessary, function order doesn't matter in Javascript... which is just as good :)

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top