Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: how to "include" other .js file in this .js file and how to "inhe- rit" from other object


Message #1 by Lin Ma <linma@b...> on Sat, 27 Jan 2001 09:11:27 -0500
> This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

--MS_Mac_OE_3063605138_189732_MIME_Part
Content-type: text/plain; charset="US-ASCII"
Content-transfer-encoding: 7bit

on 27/1/01 2:11 pm, Lin Ma at linma@b... wrote:



If I have a javascript object defined in a .js file as a "base" object, now
I want to extend it in other .js file so that the common behavior could be
implemented once for all others. Is it possible? how to do it? Thanks in
advance. 

i.e. 
in base.js 

it has 
function base() 
{ 
   this.m_basevar1 = null;
} 

function base_Method1( param )
{ 
   this.m_basevar1 = param;
   ... ... 
   return;      
} 

-------------------------

in child1.js (how do I do include base.js?)

I would like to have
founction child1() 
{ 
   this.m_child1var1 = null;
} 

function child1_Method1( param )
{ 
   /* 
   do something like:
   this.m_basevar1 = param;   //as if it inherits the m_basevar1 from "base"
   */ 
} 
--------------------------
and in the place where using this child1 would be like:

   var o = new child1();
   o.child_method1("something");
   
  /*also 
   o.base_method1("something"); //as if it inherits the base_method1 from
"base" 
   */ 
       
Is it doable? ---


Hi,
All you have to do is implement the .js file when the html file is loading.
To do this you need to use the
"src" property of the <script> tag:

<script src="pathtoscript/script.js"></script>

If you place this along with the javascript that you write in the page you
will be able to access any functions it holds. 



  Return to Index