473,625 Members | 3,251 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Prototype Object.extend(n ew Base() | Hash | Hash.prototype) usage:

I've noticed Object.extend used in a few different ways and I'm having
trouble distinguishing why certain usages apply to a given situation.
>From 1.5.0 prototype.js
[1] On line 804 Ajax.Base is defined as follows:

Ajax.Base = function() {};
Ajax.Base.proto type = {
setOptions: function(option s) { <...>

[2] Now later on line 821:

Ajax.Request = Class.create();
<...>
Ajax.Request.pr ototype = Object.extend(n ew Ajax.Base(), {
_complete: false, <...>

[3] Preceding that on lines 636 and 664 respectively we have:
Object.extend(H ash, {
toQueryString: function(obj) {

Object.extend(H ash.prototype, {
_each: function(iterat or) {
for (var key in this) { <...>
[4] on line 664
var Enumerable = {
each: function(iterat or) {
<...>
Object.extend(E numerable, {
map: Enumerable.coll ect,

[1] Seems to be going about things in a traditional manner. No class
create(). What exactly is the point of class.create()? It seems highly
redundant.

[2] There's the assignment operator and Object.extend. Would
Object.extend(A jax.Request.pro totype,new Base());
Object.extend(A jax.Request.pro totype, { ... } );
do the same thing?

[3] I'm not sure when / when not to use the prototype keyword ...
actually I don't know what it's for at all! In this example it does it
both ways. What's the difference? Similar situation with [4] and the
illustratory alternative I presented in [2]. Would Ajax.Request
( without .prototype) be correct? Or would that be broken somehow? I
wasted some time experimenting in Firefox with this but Javascript is
pretty fluffy and things like this tend to slip by ~kind of~ working.

Clarification would be greatly appreciated.

Mar 27 '07 #1
3 3576
On Mar 27, 12:48 pm, "jacob...@gmail .com" <jacob...@gmail .comwrote:
I've noticed Object.extend used in a few different ways and I'm having
trouble distinguishing why certain usages apply to a given situation.
From 1.5.0 prototype.js
You're lost :-)

Prototype.js help is on the Ruby on Rails spinoffs group:

news:rubyonrail s-spinoffs
<URL: http://groups.google.com.au/group/ru...pinoffs?lnk=li >
--
Rob

Mar 27 '07 #2
On Mar 27, 12:48 pm, "jacob...@gmail .com" <jacob...@gmail .comwrote:
I've noticed Object.extend used in a few different ways and I'm having
trouble distinguishing why certain usages apply to a given situation.
In my first reply I refrained from further comment, however on reading
your post again there are some sections that deserve comment here.

Firstly, I hope you understand the difference between the Prototype.js
library that is written in javascript and intended to be used with the
Ruby on Rails environment, and the javascript prototype property of
objects.

It is a very poorly named library.
From 1.5.0 prototype.js
To help avoid confusion with the javascript prototype property, the
library is normally referenced as "Prototype. js".
>
[1] On line 804 Ajax.Base is defined as follows:

Ajax.Base = function() {};
Ajax.Base.proto type = {
setOptions: function(option s) { <...>

[2] Now later on line 821:

Ajax.Request = Class.create();
<...>
Ajax.Request.pr ototype = Object.extend(n ew Ajax.Base(), {
_complete: false, <...>

[3] Preceding that on lines 636 and 664 respectively we have:
Object.extend(H ash, {
toQueryString: function(obj) {

Object.extend(H ash.prototype, {
_each: function(iterat or) {
for (var key in this) { <...>

[4] on line 664
var Enumerable = {
each: function(iterat or) {
<...>
Object.extend(E numerable, {
map: Enumerable.coll ect,

[1] Seems to be going about things in a traditional manner. No class
create(). What exactly is the point of class.create()? It seems highly
redundant.
That is definitely for the Prototype.js news group - I'd like to know
the answer myself. The "official" Prototype.js documentation on
Class.create is at:

<URL: http://www.prototypejs.org/api/class >

and says:

Prototype's object for class-based OOP.

Currently, inheritance is handled through Object.extend.
create

create() -Function

Returns an function that acts like a Ruby class."

>
[2] There's the assignment operator and Object.extend. Would
Object.extend(A jax.Request.pro totype,new Base());
Object.extend(A jax.Request.pro totype, { ... } );
do the same thing?
The documentation says:

extend

Object.extend(d est, src) -alteredDest

Copies all properties from the source to the destination object. Used
by Prototype to simulate inheritance (rather statically) by copying to
prototypes.
[3] I'm not sure when / when not to use the prototype keyword ...
actually I don't know what it's for at all!
Then best you learn - it is fundamental to the object-oriented aspects
of the language. Try the following two articles, take your time
getting through them:

<URL: http://www.litotes.demon.co.uk/js_in...te_static.html >

<URL: http://www.jibbering.com/faq/faq_notes/closures.html >

In this example it does it
both ways. What's the difference? Similar situation with [4] and the
illustratory alternative I presented in [2]. Would Ajax.Request
( without .prototype) be correct? Or would that be broken somehow? I
wasted some time experimenting in Firefox with this but Javascript is
pretty fluffy and things like this tend to slip by ~kind of~ working.
Javscript, or more strictly ECMAScript Language, is not "fluffy" at
all. It adheres to a public specification that, while often
criticised as difficult to read and understand, is pretty solid in
most respects. I fear that your confusion is caused by using
Prototype.js and not understanding what or why things are happening -
there are about 3,000 lines of code to get through.

While some aspects of the javascript language have been criticised
(maybe rightly so, I'm certainly not qualified to judge either way),
its prototype-based inheritance is universally viewed as one of its
great strengths.

However, prototype-based inheritance can be difficult for those
schooled in classic OO programming to come to terms with. My only
advice there is to stop thinking of javascript in terms of classic OO
concepts (stuff like "Class.crea te" when javascript has no classes)
and approach prototype-based inheritance as a brand new concept.

Clarification would be greatly appreciated.
I'm not sure I've helped, but here's hoping. :-)
--
Rob

Mar 27 '07 #3
Thank you Rob. I'll read those links regarding the prototype keyword
(I was aware it had nothing to do with the prototype.js library - I'm
ignorant but not quite ~that~ ignorant ;). Wasn't aware there was a
prototype group either so thanks for the heads up!

Mar 27 '07 #4

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

Similar topics

5
6148
by: Martin Magnusson | last post by:
Hi! I have a class with a private member which is a pointer to an abstract class, which looks something like this: class Agent { public: void Step( Base* newB ); private:
7
5753
by: Santi | last post by:
I have two classes: Product and Fruit which inherits from Product. If I try to narrow the reference to the base type by a cast, I always get a reference to the inherited type. For example: Fruit lemon = new Fruit(); Product prod = (Product)lemon; // Now prod is a Fruit Type!! I want to get a Product reference from a Fruit object, is it possible? thank you.
4
1724
by: alee.indy | last post by:
Basically, I want to add default methods to the PHP string object so that I can do something like: $stringvar = "hello"; $stringvar -> append(" world"); // where append is some kind of prototyped function i define echo $stringvar; // "hello world"
4
1585
by: FacultasNetDeveloper | last post by:
I am extending FileSystemInfo class so that I can Implement Icomparable. My custom class looks like: Class FSFileSystemInfo Inherits FileSystemInfo : Implements Icomparable Function CompareTo(ByVal o As Object) As Integer _ Implements IComparable.CompareTo My issue comes when I try to set an instance of FSFileSystemInfo to an object that is FileSystemInfo type. Such as:
4
5239
by: Jeff | last post by:
The derived class below passes a reference to an object in its own class to its base calss constructor. The code compiles and will run successfully as long as the base class constructor does not attempt to access the object -- since m_object is not actually created and initizialized until after the base constructor has been called. Any thoughts on the practice below? class Base { public:
3
1494
by: iogilvy | last post by:
i wish to have some extended functionality added to sockets i can create my own socket class class mysocket(socket.socket): and all should be fine. Except, the sockets are created for me by the accept method, listening on port. So how can i take the standard socket created for me and create a 'mysocket'. I need a method that will initialise any new properties i have added in my class, but how can i change the class of the socket...
7
1390
by: Jessica | last post by:
Hi, I have a question referring prototypal inheritance in javascript. My example: function A() {}; A.prototype = { count: 10, doit : function () {alert ("doit");} };
1
2785
by: subramanian100in | last post by:
Consider class Base { .... }; class Derived : public Base { ...
1
2229
by: Wiinie | last post by:
print Dumper($englishTB); ==> this is a result $VAR1 = bless( { 'TEXT' => 'english- This is a text ', 'LANGUAGE' => bless( { 'ID' => '3', 'NAME' => 'English' }, 'Language' )
0
8256
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8189
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8635
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8356
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
7184
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6118
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4089
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4193
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.