473,406 Members | 2,371 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,406 software developers and data experts.

relation between prototype and Prototype.js

Hi all,

I'm very confused by the relation between "prototype" and
that "Prototype.js" library that seems to be used quite a lot
(not by knowledgeable people from this group if I understood
correctly).

For example, when I do this, I use the keyword (?) "prototype":

function Example() {
...
}

Example.prototype.val = undefined;
What is the relation between that and the "Prototype.js" library?

Is that name just plain confusing or am I just plain confused?
(both ? :)

P.S : I'm just beginning with Javascript...

May 23 '06 #1
11 1485
sh******@yahoo.fr wrote:
Hi all,

I'm very confused by the relation between "prototype" and
that "Prototype.js" library that seems to be used quite a lot
(not by knowledgeable people from this group if I understood
correctly).

For example, when I do this, I use the keyword (?) "prototype":

function Example() {
...
}

Example.prototype.val = undefined;
What is the relation between that and the "Prototype.js" library?

Is that name just plain confusing or am I just plain confused?
(both ? :)

Just plain confused!

Forget about Prototype.js and learn how to work with core JavaScript.
Once you are up to speed with the language, you will be in a better
position to evaluate toolkits.

--
Ian Collins.
May 23 '06 #2
shypen42 said:
Hi all,

I'm very confused by the relation between "prototype" and
that "Prototype.js" library that seems to be used quite a lot
(not by knowledgeable people from this group if I understood
correctly).

For example, when I do this, I use the keyword (?) "prototype":

function Example() {
...
}

Example.prototype.val = undefined;
What is the relation between that and the "Prototype.js" library?

Is that name just plain confusing or am I just plain confused?
(both ? :)

P.S : I'm just beginning with Javascript...


'prototype' is to do with the object-based side of javascript - you don't
need to know about this unless you want to build your own custom objects.
You're probably best off just learning the basics of the language first.

'Prototype.js' is a library of prewritten javascript code that you can use
to make it easier to design cross-platform js applications. Among other
things, the designers of the toolkit will have worked out all the tricky
bugs that stop code running the same on all browsers, and encapsulated
this in a simple api that just works the way you want. I.e. you write code
to do what you want regardless of the browser, and their code sorts out
the nitty gritty details of how to implement this on Internet Explorer
compared to Firefox, etc. This might be worth learning about, but probably
not until you've got some practice writing simple stuff first.

--
http://www.niftybits.ukfsn.org/

remove 'n-u-l-l' to email me. html mail or attachments will go in the spam
bin unless notified with [html] or [attachment] in the subject line.

May 23 '06 #3
sh******@yahoo.fr wrote:
I'm very confused by the relation between "prototype"
and that "Prototype.js" library that seems to be used
quite a lot (not by knowledgeable people from this
group if I understood correctly).
The people who wrote Prototype.js were not very familiar with javascript
(and apparently did not like what they did now about it, so tried to
make it 'like' another language more to their liking). Most of the
people writing here like javascript (and many understand it, more or
less, as well) so they (we) don't have much use for that library.
For example, when I do this, I use the keyword (?)
"prototype":
It is not a keyword. Javascript's keywords are defined in ECMA 262 3rd
Ed. Section 7.5. "prototype" is a property name that is emplyed as the
name of a proeprty of function objects that is used when a fucntion is
used as a constructor as the source of the vlaue for the internal
[[Prototype]] property of the constructed object. The internal
[[Prototye]] property of objects is how javascript objects inherit
proerties from other objects.
function Example() {
...
}

Example.prototype.val = undefined;
So, if an object is constructed with:-

var obj = new Example();

- the resulting object does not have a - val - property itself, but it
does inherit one through its internal [[Prototype]] property, which is
assigned its value from the - Example - function's (public) prototype
property.
What is the relation between that and the "Prototype.js"
library?
The name of the "Prototype.js" library is arbitrary and has no clear
relationship with the prototype inheritance used in javascript (except
by coincidence).
Is that name just plain confusing
The name certainly is confusing.
or am I just plain confused?
(both ? :)


You may be confused as well ;-)

Richard.
May 23 '06 #4
Andy Baxter wrote:
shypen42 said:
I'm very confused by the relation between "prototype"
and that "Prototype.js" library that seems to be used
quite a lot (not by knowledgeable people from this
group if I understood correctly).
<snip> 'Prototype.js' is a library of prewritten javascript code
that you can use to make it easier to design cross-platform
js applications.
More likely to avoid addressing the issues of designing cross-platform
js applications.
Among other things, the designers of the toolkit will have
worked out all the tricky bugs that stop code running the
same on all browsers,
That is rather optimistic, and patently not true. It is not a couple of
weeks since someone posted a question here asking how to detect
environments where the prototype.js library did not work (which includes
all IE versions prior to 6, for example, and I have seen it behaving
inconsistently in recent Opera browsers when attempting AJAX). Which
means that not only have its authors failed to work out those issues but
they have also failed to provide some clear indication in the library of
when it is trying to operate in an environment that does not support it.
and encapsulated this in a simple api that just works the
way you want.
Where it 'works', the rest of the time it just errors out and denies any
possibility of clean degradation.
I.e. you write code to do what you want regardless of the
browser, and their code sorts out the nitty gritty details
of how to implement this on Internet Explorer compared to
Firefox, etc.
Where "Internet Explorer" means 'a sub-set of possible configurations of
IE 6' and "etc" is not a very long list at all.
This might be worth learning about, but probably not until
you've got some practice writing simple stuff first.


Once some experience has been gained addressing the issues of
cross-browser design Prototype.js probably won't look like a good idea
at all.

Richard.
May 23 '06 #5
Richard Cornford said:
Once some experience has been gained addressing the issues of
cross-browser design Prototype.js probably won't look like a good idea
at all.

Richard.


OK, sorry. Do you know of any toolkits that are worth using in this
respect? I'm using dojo (dojotoolkit.org) at the moment. Do you think it's
better to use a toolkit or just work through all the problems yourself??

--
http://www.niftybits.ukfsn.org/

remove 'n-u-l-l' to email me. html mail or attachments will go in the spam
bin unless notified with [html] or [attachment] in the subject line.

May 23 '06 #6
Andy Baxter wrote:
Richard Cornford said:
Once some experience has been gained addressing the issues of
cross-browser design Prototype.js probably won't look like a
good idea at all.


OK, sorry. Do you know of any toolkits that are worth using in
this respect? I'm using dojo (dojotoolkit.org) at the moment.
Do you think it's better to use a toolkit or just work through
all the problems yourself??


It is crazy not to re-use code in some form or another. The precise
level at which you pitch code re-use is (certainly has been) the subject
of quite heated debate, and I don't have time to do the subject justice
tonight. You might be well advised to do an archive search for the
threads where the subject has been debated (the threads where more than
just a couple of the regulars contributing would probably be most
useful). I think the keyword 'library' would make a reasonable starting
point for an archive search.

To date I have not seen a single publicly available general
library/toolkit/framework that I would consider appropriate for general
Internet use.

Richard.
May 23 '06 #7

Andy Baxter wrote:
Richard Cornford said:

OK, sorry. Do you know of any toolkits that are worth using in this
respect? I'm using dojo (dojotoolkit.org) at the moment. Do you think it's
better to use a toolkit or just work through all the problems yourself??
Andy Baxter wrote: Richard Cornford said:
Once some experience has been gained addressing the issues of
cross-browser design Prototype.js probably won't look like a good idea
at all.


OK, sorry. Do you know of any toolkits that are worth using in this
respect? I'm using dojo (dojotoolkit.org) at the moment. Do you think it's
better to use a toolkit or just work through all the problems yourself??


I'm no expert but these are my impressions so far...

I like Ruby a lot but don't want JavaScript to look like Ruby. It's an
extra layer. I was avoiding Prototype.js for a while; however, now with
the very cool .rjs templates in Rails, Prototype.js is becoming more
tightly integrated into Rails. I think this dependence is unfortunate
but the .rjs templates are very cool and big timesavers. As Rails
becomes more popular, it is inevitable that Prototype.js will also
become more popular. Hopefully Prototype.js will continue to improve.

I tried a bit of Dojo. It is a big library and seems like it might be
hard to understand it. Also the demo sites all seemed very slow. The
dynamic loading of libraries (or some such fanciness) could have been a
problem for speed? All this could be wrong but I only found things I
didn't like and never went "Wow this is cool!". Also the markup for
Dojo widgets seems like a nightmare. They are able to claim
non-intrusive JavaScript but the HTML tags have many attributes to get
info to the JavaScript. Seems like a complicated way to avoid a tiny
bit of easily understandable JavaScript.

The ajax toolbox looks good http://www.ajaxtoolbox.com but the license
may cause you trouble.

I've been enjoying the connection.js and event.js libraries from Yahoo!
UI

http://developer.yahoo.com/yui/

The Yahoo! dragdrop.js library seems reasonably good too. However I
don't like how it is necessary for every draggable element to have an
id. I'll live with making up dummy id's for elements for now. I hope
they eliminate this requirement soon. Also I don't know if you can set
the scope for the interesting moment functions. I haven't found any
docs indicating yes.

Wading thorough all these libraries is a lot of work. You'll have to
experiment. Certainly the Yahoo! UI core libraries are worth a look.

- Peter

May 23 '06 #8
On Tue, 23 May 2006 23:48:53 +0100, Andy Baxter
<ne***@earthsong.null.free-online.co.uk> wrote:
Richard Cornford said:
Once some experience has been gained addressing the issues of
cross-browser design Prototype.js probably won't look like a good idea
at all.


OK, sorry. Do you know of any toolkits that are worth using in this
respect? I'm using dojo (dojotoolkit.org) at the moment.


I use a very recently installed IE6, it's basically standard, very few
changes (a few tweaks to settings nothing particularly strange) but
when I click on the demo mail application on their sample
applications, most of the time it completely locks up the browser - I
think that is cache related - if I enable aggressive caching, then I
get to see the application, complete with javascript errors as it
builds - of course it's quite difficult to test as F5 completely
resets state.

Now, for me, that level of quality in a flagship application is
suggestive of poor quality. Of course it's a complicated
functionality, and certainly impressive what you can do with it, but
it's a question of how much work you have to do to get it to release
quality.

Libraries are great for prototypes, but I've never seen a release
quality product come from a library, the compromises of being general
and not quite targetted at exactly what you want create too many bugs
in what is very disperate execution environment.

Jim.
May 23 '06 #9
pe**********@gmail.com wrote:
The ajax toolbox looks good http://www.ajaxtoolbox.com but the license
may cause you trouble.


Why so?

The only thing my "license" tries to prohibit is someone taking my code and
publishing it on their site for everyone to download. And this is mainly
because it's a huge pain for me when people submit bug reports, change
requests, and other comments based on outdated code that was obtained from
some other source than my site.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
May 24 '06 #10
Matt Kruse wrote:
pe**********@gmail.com wrote:
The ajax toolbox looks good http://www.ajaxtoolbox.com but the license
may cause you trouble.


Why so?

The only thing my "license" tries to prohibit is someone taking my code and
publishing it on their site for everyone to download. And this is mainly
because it's a huge pain for me when people submit bug reports, change
requests, and other comments based on outdated code that was obtained from
some other source than my site.


I understand the reasoning and it is good. Since your library is a
utility-type library, the license makes it difficult for people to
encorporate your library in an open source project with a more liberal
distribution license like MIT or BSD or even GNU. It is true that you
gave me permission to do this for one project; however, what if someone
want's to redistribute my project on their site? It is fine with me but
do they need to ask your permission? It either gets a little
restrictive or at least a little confusing.

For someone who wants to use your library in a contract job there would
be no problem.

Peter

May 24 '06 #11
Andy Baxter wrote:
'prototype' is to do with the object-based side of javascript - you don't
need to know about this unless you want to build your own custom objects.
You're probably best off just learning the basics of the language first.


Non sequitur. That JavaScript, or ECMAScript implementations for that
matter, are object-based, if not object-oriented, programming languages,
even if it is not obvious due to implicit scope chain resolution of
identifiers, is one important part of the "basics of the language".
PointedEars
--
A man who works with his hands is a laborer; a man who works with his
hands and his brain is a craftsman; but a man who works with his hands
and his brain and his heart is an artist.
-- Louis Nizer, lawyer (1902-1994)
May 26 '06 #12

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

Similar topics

8
by: Elf M. Sternberg | last post by:
One of the complaints about prototype.js (google for it if you're not familiar with it) is that it's poorly documented. I have this inkling that the key to understanding prototype.js is in the...
8
by: Robert | last post by:
Hi, I can use "with" like this: function MyObject(message) { this.message = message; } function _MyObject_speak() {
2
by: stephane | last post by:
Hi all, What I am trying to achieve is an 'inherits' method similar to Douglas Crockford's (http://www.crockford.com/javascript/inheritance.html) but that can enable access to the superclass'...
4
by: lkrubner | last post by:
I'm reading an essay, I think one of Crockford's, and it has this example in it: function Demo() { } Demo.prototype = new Ancestor(); Demo.prototype.foo = function () { } ; Does Ancestor now...
3
by: Terrence Brannon | last post by:
I don't know what Postgres considers a relation and had no intention of creating one when piping my schema to it... I always DROP TABLE before CREATE TABLE, so here are the ERRORS emitted when...
21
by: Rob Somers | last post by:
Hey people, I read a good thread on here regarding the reason why we use function prototypes, and it answered most of my questions, but I wanted to double check on a couple of things, as I am...
7
by: Juris Krumins | last post by:
I have a problem with postgresql tables. periodicaly, I would say frequently about 5-10 time per hour i have such errors in my server log file: 2004-04-14 12:23:32 ERROR: cache lookup of...
6
by: mmcloughlin | last post by:
I'm learning about objects and am trying to figure out how basic inheritance works. I've got into the habit of explicitly setting the prototype object with an object literal as it seems to make the...
5
by: Daz | last post by:
Hi everyone. My query is very straight forward (I think). What's the difference between someFunc.blah = function(){ ; } and
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.