ARTICLE

Using Inheritance in JavaScript

Posted by Walter Scott Articles | Visual Basic 2010 September 13, 2011
With the help of this article we can be easily find parent class inherit by child class in JavaScript.
 
Reader Level:

Introduction: Using inheritance in javascript.

Step:1 Open visual studio.

  • Select website option and click asp.net website.

  • Default.aspx page open.
asp.gif

Step:2
Go to solution explorer option and right click.
  • Select add new items option.

  • Select jscript files.
jscript1.gif

Step:3
Now we write a code in jscript file.

Code :

Type.registerNamespace("sachin");
sachin.car = function (strmake, strmodel, stryear) {
    this
._make = strmake;
    this._model = strmodel;
    this._year = stryear;
};
sachin.car.prototype =
{
    get_make: function ()
    {
        return this.get_make;
    },
    get_model: function () {
        return this.get_model;
    },
    get_makeandmodel: function () {
        return this._make + "" + this._model;
 },
    get_year: function () {
        return this.get_year;
 },
  dispose: function () {
 alert("hi");
    }
};
sachin.car.registerClass("sachin.car");
Type.registerNamespace("sachin");
sachin.ash = function (strMake, strModel, strYear, strDriveType) {
sachin.ash.initializeBase(this,[strMake, strModel, strYear]);
 this._DriveType = strDriveType
    };
sachin.ash.prototype =
{
 get_DriveType: function () {
  return
this._DriveType;
    },
 dispose: function () {
   alert("Disposing instance of class ash");
    }
};
sachin.ash.registerClass("sachin.ash",sachin.car);

Step:4  Now again go to solution explorer and right click.

  • Add webform in asp.net page.

  • Now we right a code in source.
webforms.gif

Code: 

     
<title> my ajax</title>
      <
script language = "javascript" type ="text/javascript">
      function Button1_onclick() {
      var car = new sachin.car('hero', 'driver', 'year');
           alert(car.get_makeandmodel());
           alert(car.get_year());
           var ash = new sachin.ash('hero', 'driver', 'year')
           alert("ash make and model:" + ash.get_makeandmodel());
            alert(ash.get_year());
           alert(ash.get_DriveType());
           return false;
       }</script>

Step :5 Now we press F5 and run a program.

result2.gif

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Diagram
Become a Sponsor