Home > Web Front-end > JS Tutorial > Alternative implementation of JScript overloading_javascript skills

Alternative implementation of JScript overloading_javascript skills

WBOY
Release: 2016-05-16 19:20:55
Original
821 people have browsed it

JScript is not an object-oriented language, it is just object-based. It does not have the concept of overloading, but there is still a way to achieve overloading in a sense through some tricks.

First define a base class TestA, which overrides the toString method inherited from Object.

Note: The toString method is used to serialize objects. For example, alert(a) is equivalent to alert(a.toString());


Reference:
function TestA (Name)
{
this.Name = Name;
this.toString = function ()
{
return this.Name;
}
}

Next we implement a derived class TestB of the TestA class:
Reference:
function TestB()
{
TestA.apply(this, arguments);
}

Run the following code to see that TestB has inherited the members of TestA:


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template