JavaScript let's you do proper encapsulation using closures like so:
function Person(name) {
this.setName = function(value) {
name = value;
}
this.getName = function() {
return name;
}
}
There's a memory cost to this, though: every instance of the Person
class will get it's own
On Mar 9, 1:15 pm, SamuelXiao foolsmart2...@gmail.com wrote:
Sorry for my unclear explanation, the following is all my JavaScript
code,
// script01.js //
obj = new Object();
obj.f1 = eventHandler;
window.onload = obj.f1;
window.onunload = function(){};
function eventHandler(){
There's another, less bullet-proof solution, which involves catching
and stopping all click (an possibly keypress) events on links.
But what about situation when someone type new url , press home button
or one from favourites toolbar?
Quleczka
The first thing that hit my mind was: why would you want your SELECT
element to behave that way? It just seems user unfriendly to me. You
obviously want to present the user a bunch of options, and then
disable certain options based on the user's selection. Now, if I
imagine how this would work in
But what about situation when someone type new url , press home button
or one from favourites toolbar?
That's the You could always fallback on a regular alert for page
refreshes and the like. bit.
-- T.J.
On Mar 10, 10:17 am, Quleczka qulec...@gazeta.pl wrote:
There's another, less
Quoting myself:
You could always fallback on a regular alert for page refreshes and
the like.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
Prototype script.aculo.us group.
To post to this group, send email to
Oups, let's do it again.
Hi It,
I'm agree with Maarten, but if you still like to hide some option,
here is two way to do it:
select id='mySelect'
option id=mS1 value='1'One/option
option id=mS2 class=oClass value='2'Two/option
option id=mS3 value='3'Tree/option
option id=mS4 class=oClass
Hi AI C,
very difficult to imagine what could be your problem, if you are not
sure that it's not opacity, verify with Firebug, and you will have the
assurance that it is or not.
btw, is it possible to have live testing?
And do you know how to reproduce the error ??
--
david
On 7 mar, 16:18, Al
Hi David,
I would like to be able to click the edit button on one field, for
example the title and then edit the title, description and other
fields at the same time and then save them using a single 'Save'
button and save all the fields.
Many thanks,
Darryl
On Mar 10, 12:00 pm, david
Thanks for the replies guys.
Sometimes JS's flexibility can catch me out. I guess there is no right
or wrong way to do anything. Just things to consider.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
Prototype
Hello,
I just had a bug the morning, I still dont understand why it did not
work
I have two classes,
I call Foo.select on element click.
Foo.select call Bar.action
When creating multiple Bar, the Bar.action call is always the last
instanciated function...
Ok that's not very clear, but imagin
hey hi
I have an element which I wat to be on top (zIndex) after drag.
but if I try f.i
new Draggable(mydiv,{onEnd: function() {
$(mydiv).addClassName('whatever');
$(mydiv).setStyle({ zIndex:'52' });
Hi,
Your options object is common to all instances of Foo, because you
declared it that way:
[snip]
Foo = Class.create({
options: $H({'onSelect' : false}),
initialize: function(element, options) {
[snip]
'options', just like 'initialize', is
Hi Quleczka
All your suggestions look good and probably are great technique for
getting this done. BUT, no matter what I do, no matter ghow I code
this - and I have now tried at least a dozen different ways, I get the
exact same problem - as soon as I address my form, I get an error -
either
On 10 Mar, 07:25, Jim Higson j...@wikizzle.org wrote:
On Monday 09 March 2009 21:51:05 kangax wrote:
It's possible that we'll introduce a custom `hasOwnProperty` in later
revisions.
Makes sense.
if( !hasOwnProperty )
hasOwnProperty = function hasOwnProperty(){ ... };
Thanx a lot,
now it seems clear to me.
I must confess that javascript and prototype are sometimes magical for me
and it's not obvious to understand the underlying process of Class.Create
...
Well thanx again.
On Tue, Mar 10, 2009 at 2:33 PM, T.J. Crowder t...@crowdersoftware.comwrote:
Hi,
Right, when I run that script (in Firefox 3) The following alert boxes
appear:
HTML !!!
toto2
toto2 test2
SVG !!!
[object SVGAnimatedString]
I then get _t.addClassName is not a function in the error console
Debugging the script shows me that _t doesn't appear to have a
prototype attribute.
For the first time something is happening - though I am not sure what.
Explorer is hanging up after giving a 'null' response for the alert
below - but, firefox is not even hitting the alert and is processing
normally, thogh it does not have the code to complete the AJAX
request, just redirects
Hi
I am wondering how to make a drag and drop function actually pass
values - I'm trying to build a photo gallery function where you have a
bunch of photos you've uploaded and you are going to drag them to a
(box) that represents a certain photo gallery.
I'm a php coder and while I've used
Could someone please help me understand what is going on here? Note
that I want the event to fire regardless of where focus is.
The following works fine on IE6, IE7, and chrome. Not working on ff
3.0.7.
htmlhead
script src=prototype.js type=text/javascript /script
script type=text/javascript
Hi,
Observe document, rather than document.body:
Event.observe(document, 'keydown', myEventHandler);
That works with FF3, IE7, and Opera9 (all on Windows).
HTH,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available
On Mar 10, 2:30 pm,
Hi,
Also works in Chrome. I noticed you mentioned it specifically, so...
Haven't tried Safari.
OT, you might also want to use a doctype in your page; Prototype
essentially requires one, and it's good practice.
-- T.J. :-)
On Mar 10, 3:24 pm, T.J. Crowder t...@crowdersoftware.com wrote:
Hi,
On Tuesday 10 March 2009 14:06:17 kangax wrote:
It's possible that we'll introduce a custom `hasOwnProperty` in
later revisions.
Makes sense.
if( !hasOwnProperty )
hasOwnProperty = function hasOwnProperty(){ ... };
I was thinking of something like:
var
Hi, ColinFine, in my javascript code. The prev.js is to do links with
URL preview. It is expected to show a preview box with linked
content. However, in my testing, prev.js can work on its own, when it
comes to using both script01.js and prev.js together, it doesn't
work. My question is how
I think the easiest way to do this will be to write your own editor
view, and substitute that for a portion of your regular page using
Ajax.Updater. That way you'll be able to customize it to the thing
you're editing pretty directly. It's a long slog extending the
InPlaceEditor to give it
Prototype really really likes a standards-compliant page to work in --
that means you need a doctype because without one, you fail at the
first line. This isn't for any reasons of standardista purity, the
recommendation is there simply because when you mess with the DOM, you
need to start
On Mar 10, 11:30 am, Jim Higson j...@wikizzle.org wrote:
On Tuesday 10 March 2009 14:06:17 kangax wrote:
[...]
Writing `hasOwnProperty.call(object, property)` is a bit tedious. Why
not just encapsulate the `call`?
Ah, yes, I imagined we'd be adding hasOwnProperty to Object.prototype to
i need to enter to the page with making all scripts on it. so i need
to download it via seeds (hhtp headers). and make all scripts. how can
i do it?
i thought via Ajax.Update i can do it. but something is wrong.
i don't know what to do with parameters. because i need to download
all page.
script
As I suspect is common with many Prototype shops, over here at
Zenbe.com, we're making HEAVY use of Function#bind(). We've been
using a custom version of the bind() method for a while now, and I've
recently added a couple enhancements that I'd like to get people's
opinions on - especially that
*dooh* sorry - shoulda just stuck that code in a Pastie, like so:
http://pastie.org/412930
FWIW, I just collected some stats on our code to determine what %'age
of cases are binding arguments .vs. just binding an object. It looks
like it's ~98.5% (2170 of 2200 calls to bind pass a single object
2009/3/10 Robert Kieffer bro...@gmail.com:
*dooh* sorry - shoulda just stuck that code in a Pastie, like so:
http://pastie.org/412930
FWIW, I just collected some stats on our code to determine what %'age
of cases are binding arguments .vs. just binding an object. It looks
like it's ~98.5%
Hi,
On the face of it, I like the thought of skipping the arguments prep
in the no-args case, but have you done any profiling to be sure that
it really has a measurable benefit? Same question on inlining the per-
call arguments concatenation... Without a solid, measurable benefit,
I'd avoid
On Mar 10, 12:41 pm, Robert Kieffer bro...@gmail.com wrote:
[...]
- bind() is so ubiquitous for us that performance is a top priority.
Your version is still slower than it could be ; )
`$A`, `shift`, `apply` - all of those slow things down for no good
reason.
Take a look at
Robert, have you looked at the implementation in trunk ?
I rewrote most of it not long ago after serious benchmarking and
taking into consideration smart(er) memory management.
This kind of discussion belongs ont the core mailing list BTW, to make
sure no one misses it!
Best,
Tobie
On Mar
I won't speak to your .bind() mods as I've not reviewed them, but in
general, for the majority case of simply binding the context of a function
to an object in order to fix the this keyword within the function, it is
ALWAYS just easier and MUCH MUCH faster to early bind to a variable
outside the
Explorer is hanging up after giving a 'null' response for the alert
below - but, firefox is not even hitting the alert and is processing
normally, thogh it does not have the code to complete the AJAX
request, just redirects to redo the original page
If you don't use event.stop() for is just
This should get you started (requires scriptaculous)
table border=1 cellpadding=5
tr
td valign=top
ul id='fList'
liApples/li
liGrapes/li
I do agree there are just times when .bind() is called for, but I am fairly
certain the majority of people WAY overuse it.
+1 to that, where you're defining the function inline. Where you're
not, while this may be faster:
var self = this;
handler = function() {
Function.prototype.bind() is making it's way into ES 3.1. IT will be
interesting to see it's performance once it's native.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
Prototype script.aculo.us group.
To post to
On Mar 10, 3:27 pm, T.J. Crowder t...@crowdersoftware.com wrote:
I do agree there are just times when .bind() is called for, but I am fairly
certain the majority of people WAY overuse it.
+1 to that, where you're defining the function inline. Where you're
not, while this may be faster:
Kangax...
2) Non-bound event handler is faster at run time, as it accesses
`onClick` from the proper object directly, but presumably consumes
more memory (due to extra closure, created during function expression
evaluation)
There is no extra closure because .bind() creates a closure anyway
Put the result in a hidden field and post the form, or make it a
parameter in an Ajax call. The server side of things is no different
than any regular form posting.
On Mar 10, 5:13 pm, Marian Briones mbrio...@gmail.com wrote:
I've got the drag and drop capability; it's getting it to talk to a
I guess what I wanted to say is that a function created with
Prototype's `bind` (internally) has a predictable closure - the one
that's got formed when a function was declared. And it is declared by
Prototype, inside a very slim scope (self-executing function,
surrounding
43 matches
Mail list logo