473,573 Members | 3,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Different Javascript Class syntax

I discovered this syntax on the google example of a client to their web
service.

function PagClass()
{
this.init();
}
PagClass.protot ype = {

init : function() {
this.m_bInited = true;
this.m_nTotalRo ws = 0;
this.m_nFirstRo wNum = 0;
this.m_nRowsPer Page = 0;
this.m_nNumPage s = 0;
this.m_nReporti d = 0;
this.m_nResultN umStart = 0;
this.m_strStart = "";

},

foo: function() {...},
bar: function() {...}
}
This seems like a very elegant way to create classes in javascript,
gives you a constructor and lists methods as comma separated
properties.

My colleague is suspicious that there may be excessive runtime overhead
associated with the prototype, property list way of doing this.
Anybody know for sure?

Bob Gulian

Apr 3 '06 #1
1 1202
"bg*****@gmail. com" <bg*****@gmail. com> writes:
I discovered this syntax on the google example of a client to their web
service.
(This syntax apparently being the object literal notation)

function PagClass()
{
this.init();
} PagClass.protot ype = {

init : function() { .... },

foo: function() {...},
bar: function() {...}
}
This seems like a very elegant way to create classes in javascript,
gives you a constructor and lists methods as comma separated
properties.
It won't be a class, but it has similarities. You miss the properties
added to default prototype, i.e.,
PagClass.protot ype.constructor (equals PagClass)
.... well, that's about it :)
My colleague is suspicious that there may be excessive runtime overhead
associated with the prototype, property list way of doing this.
Anybody know for sure?


Hardly. You do create an extra object instead of using the perfectly
good object already created in PagClass.protot ype, but on the other hand,
you use the internal language implementation to populate it with
properties instead of assigning each by yourself.
All in all, I doubt there is a measureable difference between using
an object literal and assigning to the existing constructor.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Apr 3 '06 #2

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

Similar topics

6
1995
by: Alex Fitzpatrick | last post by:
Just by way of introduction, I'm currently the principal developer and maintainer of the a JavaScript editor plug-in for Eclipse. https://sourceforge.net/projects/jseditor/ The plug-in as it stands supports syntax highlighting and outlining of functions, classes and their methods.] When I took over the project in June it was for the...
1
1345
by: Paul Aspinall | last post by:
Can anyone recommend a good editor for coding Javascript?? ie. once which has 'intellisense' type prompting etc. If there isn't an editor with this built-in, is there a program which does it as a quick-ref help tool?? Thanks Paul
1
3842
by: jarit | last post by:
Hi, Found these coding guidelines for C#, HTML, Javascript, Java, HTML, PL/SQL, T-SQL, VB and VBScript. Well written and free to download. www.demachina.com/products/swat Jeroen
8
3642
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
17
5054
by: romixnews | last post by:
Hi, I'm facing the problem of analyzing a memory allocation dynamic and object creation dynamics of a very big C++ application with a goal of optimizing its performance and eventually also identifying memory leaks. The application in question is the Mozilla Web Browser. I also have had similar tasks before in the compiler construction area....
26
2516
by: Cliff Williams | last post by:
Can someone explain the pros/cons of these different ways of creating a class? // 1 function myclass() { this.foo1 = function() {...} } // 2a
3
4588
by: jackchang1 | last post by:
Hi I want to develop a Java application to check the syntax of Javascript code and I am thinking about using Rhino. But I don't know where to start and there is no document for this. Has anybody done this before? or can Rhino be embedded in my Java application to check the syntax of JavaScript code? I thought it is possible. Thanks!
1
1799
by: Cartoper | last post by:
I have this book "Beginning JavaScript for Practical Web Development, Including AJAX" and in it the author is using javascript syntax I don't understand. It is <class name>={ <function name>:function(params) { }, <function name>:function(params) {
1
5894
by: Constantine AI | last post by:
Here is the situation i am currently trying to update a sales order using PHP and javascript. When you click on the edit button it brings you a new site page with existing sales order details within. I am wanting the order lines to be within option boxes so they can modify the order if they wish. I created some javascript for the create sale site...
0
7777
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7686
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8016
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7773
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5584
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5289
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3730
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2197
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1038
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.