473,769 Members | 6,267 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

prototype.js object persistance

I've created a new class using prototype.js. After I make the
ajax.request all references to this.myClassMet hodorVariable are lost.
Does the ajax method blow out the object persistance? I'm fairly new to
OOP javascript so could be (and probably am) overlooking some detail.
Below is the logic of what i'm trying to do.

//Javascript code
var myClass = Class.create();
myClass.prototy pe={
initialize: function(fm) {
//Static Variables
this.myMessage = 'hello';
this.myName = 'Nick';
this.frm = fm;
this.WSURL = '/some/Server/script';
this.frm.onSubm it =
this.submitForm .bindAsEventLis tener(this);
},
submitForm: function(evt) {
var pars = myMessage;
var myAjax = new Ajax.Request( this.WSURL, { method: 'get',
parameters: pars, onSuccess: this.myHandler} );
},
myHandler: function(ajaxRe sponse) {
this.myMessage( ajaxResponse.re sponseText);
},
myMessage: function(str) {
alert(str);
}
};

//HTML Code
<form name="someForm" id="someForm" method="post" action="##">
<input type="text" id="myText" />
<input type="submit" name="submit" value="submit">
</form>
<script>var testClass = new myClass('somefo rm');</script>

May 25 '06
45 3036
se*******@gmail .com wrote:
Thomas, I'll try to be respectful.
And if you read my followup as disrespectful, you have a problem. I simply
strongly disagreed with your statement, providing the same reasons you did
for your opinion: none.
I won't comment on the rest of what you said because it wouldn't be fair
since you already confessed not knowing the code base.
You misunderstood. I said that I (among others) /know/ the codebase to be
junk. That is a huge difference.
But the following comment:
[...] Rule of thumb: avoid "this" inside anonymous functions and also
in functions you pass around as references. Utter nonsense.


Makes sense when quoted out of context like you did.


I do not see where it would not make sense.
Maybe I expressed myself incorrectly. What I meant was that, when using
classes that
*There* *are* *no* *classes* in the programming languages used. That
there are, that they can be created out of the same language, is one of the
misconceptions distributed by the Prototype code. The reason is that its
author did _not_ know what he was doing (using [but] an _implementation _
of an _object-oriented_ programming language with _prototype-based_
inheritance and a _built-in_ constructor mechanism), therefore he invented
a new, seemingly multi-purpose wheel ("Object-oriented JavaScript", as if
class-based OO was the only way) with visible vertices ("initialize " etc.),
and one spoke (almost no feature tests or fallbacks). And because of this,
that wheel breaks more often than necessary. Which is the main reason why
I call it junk (the missing documentation simply adds to this).
encapsulate AJAX calls
There are no "AJAX calls".
and you pass some of the classe's methods to be invoked in callback
situations, you have to be extra careful with the "this" keyword. The
same applies to anonymous methods used as callbacks.


So in essence you say that one should know what one does, something I can
strongly agree with (see above). But that is different from what you had
stated before, hence my objection then.
PointedEars
--
When the power of love overcomes the love
of power, the world will know peace.
-- Jimi Hendrix
May 29 '06 #31
pe**********@gm ail.com wrote:
Richard Cornford wrote:
:D I am storing JavaScript in a database. And I think it
is a good idea in my particular case.
Mechanism in the database? Oh well, time will convince you
even if I cannot.


Ok, I'll bite. What is so bad about JavaScript in the
database?


Implementing the changes that are the inevitable consequences of ongoing
maintenance. Ideally an application wide javascript update can be done
by editing one file (usually a JS) in one place. That is quick and easy
(so relatively inexpensive). Going through a database modifying
executable javascript code is either very time consuming or very
error-prone (if automated) or both.

There is also the question of separating data, logic and presentation.
That is generally seen as a good idea, and frameworks have been created
to maximise that separation. Javascript code is logic, or mechanism, to
should not be mixed in with data and it certainly should not be being
put in a place where it cannot easily be seen/modified.
My application is an online store with multiple store
administrators. If two adminstrators are viewing the
same product information and one administrator edits the
product info then I store the JavaScript that will update
the any adminstrators page. When the other administrator
polls the server for new updates the server will send back
all the new JavaScript updates that were stored in the
database.
In any particular order?
This is using the database as a buffer or holding tank since
server push is not possible for me.
Or anyone else over HTTP.
Sound horrendous?
Insufficient information to judge.
When the whole system of how I am doing this came to me
it really was an "I've got it!" moment. All the code shunk
by more than 50% and became very Rails-ish.


The code shrank, or _your_ code shrank? Every line of javascript added
to the database is another line of code added to the system, and a line
of code added in a non-obvious location.

But what I have seen of Rails so far suggests that it is not suited to
an online sore anyway.

Richard.
May 29 '06 #32

Richard Cornford wrote:
pe**********@gm ail.com wrote:
My application is an online store with multiple store
administrators. If two adminstrators are viewing the
same product information and one administrator edits the
product info then I store the JavaScript that will update
the any adminstrators page. When the other administrator
polls the server for new updates the server will send back
all the new JavaScript updates that were stored in the
database.


In any particular order?


In a particular order. I'm not sure what you really want to know.

When the whole system of how I am doing this came to me
it really was an "I've got it!" moment. All the code shunk
by more than 50% and became very Rails-ish.


The code shrank, or _your_ code shrank?


My code.

But what I have seen of Rails so far suggests that it is not suited to
an online sore anyway.


Ok, my jaw dropped with this one. Why wouldn't Rails be suited for an
online store? What do you think is a better alternative? I think Rails
is well suited to an online store because an online store is just a
collection of pages and forms like most other websites. Have you played
with Rails much? It is pretty cool.

Peter

May 29 '06 #33
Richard Cornford wrote:
Ok, I'll bite. What is so bad about JavaScript in the
database?

Javascript code is logic, or
mechanism, to should not be mixed in with data and it certainly
should not be being put in a place where it cannot easily be
seen/modified.


In some cases, editing a simple .js file is painful and time-consuming. For
example, if a full release is required which will require testing and an
install window which might happen only once a week or less. In cases where
the database is much more easily updated than the filesystem, storing js in
the database might be a good idea. I've even seen jsp's stored in the db,
with a process which would retrieve the file and write it to disk before the
app server looked for it. All to be able to release changes without going
through a painful release process :)

I'm not saying it's a general good practice, but there are cases where it is
one solution to a problem.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
May 29 '06 #34
Matt Kruse wrote:
Richard Cornford wrote:
Ok, I'll bite. What is so bad about JavaScript in the
database? Javascript code is logic, or mechanism, to should not
be mixed in with data and it certainly should not be
being put in a place where it cannot easily be
seen/modified.


In some cases, editing a simple .js file is painful and
time-consuming. For example, if a full release is required
which will require testing and an install window which might
happen only once a week or less. In cases where the database
is much more easily updated than the filesystem, storing js
in the database might be a good idea. I've even seen jsp's
stored in the db, with a process which would retrieve the file
and write it to disk before the app server looked for it.
All to be able to release changes without going through a
painful release process :)


You are describing something more akin to content management, which
isn't quite the same issue.
I'm not saying it's a general good practice, but there are
cases where it is one solution to a problem.


It may be going too far to say that javascript source should never be in
a database, I am only really saying that javascript source should not be
data for an application. The data may contain statements of behaviour,
but it should not consist of the actual mechanism.

Richard.
May 29 '06 #35
pe**********@gm ail.com wrote:
Richard Cornford wrote:
pe**********@gm ail.com wrote: <snip>
When the whole system of how I am doing this came to me
it really was an "I've got it!" moment. All the code
shunk by more than 50% and became very Rails-ish.
The code shrank, or _your_ code shrank?


My code.


Which is always appealing to the individual but not necessarily good for
the system.
But what I have seen of Rails so far suggests that it is
not suited to an online sore anyway.


Ok, my jaw dropped with this one. Why wouldn't Rails be
suited for an online store?


Haven't we been discussing how an application of Rails has directly got
in the way of the primary purpose of an e-commerce site; to take money
off people? And how its use is moving the problematic dependencies out
of sight?
What do you think is a better alternative?
It is possible to use any server side technology to create a very poor
end result. Most should also tolerate the creation of a good end result,
but I would think that the most significant factor in achieving that
outcome is how well the developer(s) in question understand what they
are actually doing.

Unfortunately frameworks seem to go a long way towards stopping
developers from understanding what they are doing. Dot NET seems to be a
particular offender at present. There is a regular stream of .NET
developers posting here because they are using some 'component' and want
something extra from it in the browser, but when questioned many of them
don't even seem to appreciate that there is a separation between code
executing on the client and code executing on the server. When people
are shielded from a basic understanding of what they are doing they are
going to find it very difficult to appreciate (or even see) the more
complex issues buried under the surface.

Rails seems to imply that same shielding of details from the developer,
and it has been proposed that Rails is tying itself up with
Prototype.js, which means unreliable client-side code in situations
where the UA is unknown. So a system where the unnecessary dependencies
are implicit and the developer may not even appreciate that they exist,
let alone be in a position to mitigate.
I think Rails is well suited to an online store because an
online store is just a collection of pages and forms like
most other websites.
If that is the reality, and no dependencies on specific client-side
technologies or code-bases are inherent, then yes, that should be
suitable. However, that is not what you have been describing, nor is it
the reality of the example that has been cited.
Have you played with Rails much?
No I have not used Rails at all, nor am I likely to in the foreseeable
future. I do my server side code in Java (and very occasional JScript
ASP), but currently the demand for me to work exclusively on client-side
code is so great that I have not written any Java in the last two years,
and am unlikely to again for at least the next.
It is pretty cool.


"Cool" is so devalued as a categorisation these days that I no longer
regard it as modifying the worth of its subject.

Richard.
May 29 '06 #36

Richard Cornford wrote:
pe**********@gm ail.com wrote:
Richard Cornford wrote:

But what I have seen of Rails so far suggests that it is
not suited to an online sore anyway.
Ok, my jaw dropped with this one. Why wouldn't Rails be
suited for an online store?


Haven't we been discussing how an application of Rails has directly got
in the way of the primary purpose of an e-commerce site; to take money
off people? And how its use is moving the problematic dependencies out
of sight?


This does not seem like a solid argument against using Rails for a
site. Rails makes building many web apps much easier, faster, and with
less code which could mean less bugs and maintenance. A developer must
still pay attention and know what he is doing. No one said that Rails
developers did not need to know what is going on in the background.

Rails seems to imply that same shielding of details from the developer,


I agree with this. Wrapping everything (HTML, JavaScript) in Ruby is
one of the goals of Rails. Like you said, this could lead the unknowing
into creating a bad product. But that is their own responsibility. I'm
happy to have Rails to make my development faster. With or without
Rails I still must understand what is happening. Each developer is free
to use only as much or little of the Rails wrappers as they want. There
is no requirement to use the Rails JavaScript wrappers. However there
are some things that are being developed in Rails that is making using
these wrappers more attractive.
Peter

May 30 '06 #37
Sergio,

Thanks for being the only person to answer my questions. The rants in
this goup are worse than slashdot. To everyone opposed to prototype:
I'm not completely committed to using it. You wasted 2 pages of time
and server space without any useful insight. A good answer would have
been...rather than use prototype why don't you try this....[code
snipped here].

May 30 '06 #38
bi******@gmail. com wrote:
The rants in this goup are worse than slashdot.
Well that might be true ;)
To everyone opposed to prototype:
I'm not completely committed to using it. You wasted 2 pages of time
and server space without any useful insight. A good answer would have
been...rather than use prototype why don't you try this....[code
snipped here].


This is a place for _discussion_, not a help desk with just questions and
answers.
Even if the spawned discussion isn't exactly what you wanted, it is
nevertheless a good thing.

--
Matt Kruse
http://www.JavascriptT oolbox.com
http://www.AjaxToolbox .com
May 30 '06 #39
Matt Kruse wrote:
In some cases, editing a simple .js file is painful and time-consuming.
I have the same experiences.
For example, if a full release is required which will require testing and an
install window which might happen only once a week or less. In cases where
the database is much more easily updated than the filesystem, storing js in
the database might be a good idea.
I'ld say it's totally up to the nature of the application, and what the
project specifications consist of. That eventually might include
storage of javascript source code. But I think one should definitely be
careful with such design models, though.

The major concern I would have with this scenario is one of
performance. Javascripts loaded from the filesystem require much less
resources from the machine than a database lookup.

I have numerous js files that are automatically updated by cronjobs.
Those js files mainly hold variables coming from the database;
synchronised once a night and then used for the heavy CPU work during
the day. I don't want to toot my own horn, but I think this is better
practice than querying over-and-back all the time.
[...]
I'm not saying it's a general good practice, but there are cases where it is
one solution to a problem.


I totally agree with that evaluation.

--
Bart

May 30 '06 #40

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

Similar topics

0
980
by: Michael.McD | last post by:
Is there any consensus on the way to go when implementing object persistance to a dB? For example MHibernate v. DataObjects (x-tensive). Cheers, Michael McD
7
1258
by: Florian Loitsch | last post by:
hi, in section 10.1.8 (Arguments Object) it is stated that the "internal ] property of the arguments object is the orginal Object prototype object, the one that is the *initial* value of Object.prototype". Furthermore the Object.prototype property has attributes . My question now: what does the "initial" refer to? To the untouched prototype-object, or to the current Object.prototype? In the latter case: why would the write "initial", if...
8
3759
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 bind function. The problem with Javascript is that the "this" operator is poorly overloaded and it is often hard to understand in the context of object-oriented javascript So, let's start with the definition:
8
2061
by: Robert | last post by:
Hi, I can use "with" like this: function MyObject(message) { this.message = message; } function _MyObject_speak() {
2
3036
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' priviledged methods also. Do you know if this is possible ? In the following example, I create an ObjectA (variable a), an ObjectB which inherits ObjectA (variable b) and an ObjectC which inherits ObjectA (variable c1). The 'toString ()' method...
4
1771
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 have a function called foo? What if I have 5 different objects, all descended from Ancestor? Do
13
2575
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){}, my_meth2: function(){} }); to define new methods on the MyObj prototype object. Object.extend
5
2244
by: Daz | last post by:
Hi everyone. My query is very straight forward (I think). What's the difference between someFunc.blah = function(){ ; } and
3
3587
by: jacobstr | last post by:
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. On line 804 Ajax.Base is defined as follows: Ajax.Base = function() {}; Ajax.Base.prototype = { setOptions: function(options) { <...>
0
9589
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
10211
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
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...
0
8872
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
7409
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
6673
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();...
1
3959
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
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.