473,395 Members | 1,670 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Methord in Class

Hello Everyone,

How can I add a methord to a class? Consider the code...

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

function makeMovie(name,lead)
{
this.title = name
this.actors = lead
function showLead()
{
alert("Lead Actors are "+this.actors)
}
}

var film = new makeMovie("Whatever","Whoever")
film.showLead()

-----------

This gives an error
"Object don't support this property or methord."
Thanking You in advance,
Binny V A
http://www.geocities.com/binnyva

Jul 23 '05 #1
2 1080


bi*****@hotmail.com wrote:

How can I add a methord to a class? Consider the code... function makeMovie(name,lead)
{
this.title = name
this.actors = lead
function showLead()
{
alert("Lead Actors are "+this.actors)
}
}
Use
makeMovie.prototype.showLead = function () {
alert("Lead Actors are " + this.actors);
};
var film = new makeMovie("Whatever","Whoever")
film.showLead()

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
> How can I add a methord to a class? Consider the code...

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

function makeMovie(name,lead)
{
this.title = name
this.actors = lead
function showLead()
{
alert("Lead Actors are "+this.actors)
}
}

var film = new makeMovie("Whatever","Whoever")
film.showLead()

-----------

This gives an error


You have two choices:

As you wrote it, showLoad is a private method. This is how you can turn
showLead into a public method:

function makeMovie(name, lead) {
this.title = name;
this.actors = lead;
}
makeMovie.prototype.showLead = function () {
alert("Lead Actors are " + this.actors)
};

This is how you can turn it into a priviledged method:

function makeMovie(name, lead) {
this.title = name;
this.showLead = function () {
alert("Lead Actors are " + lead)
}
}

Notice that lead is a private member. See
http://www.crockford.com/javascript/private.html
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A,...
1
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me...
9
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
5
by: Andy | last post by:
Hi all, I have a site with the following architecture: Common.Web.dll - Contains a CommonPageBase class which inherits System.Web.UI.Page myadd.dll - Contains PageBase which inherits...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.