[Proto-Scripty] Re: Finding Class methods

2011-03-18 Thread T.J. Crowder
Hi,

The `for..in` loop enumerates the *names* of the properties in the
object and its prototype(s); your `m` is always a string because
property names are always strings. To get the property value, just
look it up as normal:

for (name in c) {
console.log(name +  [ + typeof c[name] + ]);
}

(Or instead of `typeof` you have other options[1], but you get the
idea.)

As a bonus answer, if you want to differentiate between properties on
the object itself and properties that it's inheriting from its
prototype chain, use `hasOwnProperty`:

for (name in c) {
console.log(
name +  [ + typeof c[name] + ] ( +
(c.hasOwnProperty(name) ? own : inherited) +
)
);
}

Live example: http://jsbin.com/ekimu4

[1] http://blog.niftysnippets.org/2010/09/say-what.html

HTH,
--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com

On Mar 17, 4:53 pm, greg g...@reservation-net.com wrote:
 Hi,

 Within my script I'd like to get a list of methods defined within in a
 class created with Class.create().

 If I do:
 var c = new MyShinyNewClass()
 console.log(c)
 I get a nice breakdown of variables and methods, and firebug
 differentiates the vars from the functions.

 If I do:
 for (m in c) console.log(m)
 I get a nice list of all variables and methods, but typeof m always
 returns 'string'.

 Given that firebug can differentiate between a variable and function,
 is there any way for me to do the same?

 Thanks.

-- 
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 prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



[Proto-Scripty] Re: Finding Class methods

2011-03-18 Thread mmerlin
greg,

Nothing to do with Prototype.  Standard javascript / DOM


 If I do:
 for (m in c) console.log(m)
 I get a nice list of all variables and methods, but typeof m always
 returns 'string'.

for (a in b)
always sets 'a' to be a string.  It is the 'name' of the property in
'b'.

Try console.log(typeof c.m)

--
Phil

-- 
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 prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



[Proto-Scripty] Re: Finding Class methods

2011-03-18 Thread T.J. Crowder
 Try console.log(typeof c.m)

That will look up a property m on the `c` object. You mean:

console.log(typeof c[m]);

...which will look up a property using the name contained by the `m`
variable, rather than the property with the name m.

-- T.J. ;-)

On Mar 18, 7:19 am, mmerlin mmerlin.p...@gmail.com wrote:
 greg,

 Nothing to do with Prototype.  Standard javascript / DOM

  If I do:
  for (m in c) console.log(m)
  I get a nice list of all variables and methods, but typeof m always
  returns 'string'.

 for (a in b)
 always sets 'a' to be a string.  It is the 'name' of the property in
 'b'.

 Try console.log(typeof c.m)

 --
 Phil

-- 
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 prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



[Proto-Scripty] Why is there a $super-Parameter?

2011-03-18 Thread Luke
Hi,

I'm working on my bachelor-thesis and I'm trying to understand a few things. 
I'm wondering: Why is there the construct of the $super-parameter in 
Prototype's class-implementation? Is anything wrong with calling 
this.parent.myfunction()? Why did they implement that?

This is more of a theoretical question.. I just think there must be a reason 
for the $super thing..

Does anyone have an idea?

Thanks
Lukas

-- 
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 prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



Re: [Proto-Scripty] Why is there a $super-Parameter?

2011-03-18 Thread Richard Quadling
On 18 March 2011 11:43, Luke kickingje...@gmail.com wrote:
 Hi,
 I'm working on my bachelor-thesis and I'm trying to understand a few things.
 I'm wondering: Why is there the construct of the $super-parameter in
 Prototype's class-implementation? Is anything wrong with calling
 this.parent.myfunction()? Why did they implement that?
 This is more of a theoretical question.. I just think there must be a reason
 for the $super thing..
 Does anyone have an idea?
 Thanks
 Lukas

 --
 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
 prototype-scriptaculous@googlegroups.com.
 To unsubscribe from this group, send email to
 prototype-scriptaculous+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/prototype-scriptaculous?hl=en.


parent relates to the DOM which is an object orientated model.

Javascript classes are not OOP, but prototypes. As such parent is
not appropriate.

To simulate parent in PrototypeJS, $super was defined.

http://prototypejs.org/learn/class-inheritance

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

-- 
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 prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



[Proto-Scripty] Re: Finding Class methods

2011-03-18 Thread greg
Doh!

Thank you folks for pointing out the astonishingly simple answer.

Sometimes I'm so stunned when something doesn't work, I don't see the
obvious.

-- 
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 prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



Re: [Proto-Scripty] Why is there a $super-Parameter?

2011-03-18 Thread Ryan Gahl
The answer is quite simple: because it's convenient.

Convenience is an interesting thing. You seem to be a logical type,
postulating that there must be something beyond just convenience here,
because if it can be done without this construct, why add the construct,
right? That takes the human part of the equation right of the picture
though. The truth is that humans, even programmers, are irrational. We
sometimes do things just because, or barring that, just because it achieves
a certain stylistic property that pleases us.

In this case, I think it's both just because and because it's pretty. At
a minimum, it's convenient.




On Fri, Mar 18, 2011 at 8:13 AM, Luke kickingje...@gmail.com wrote:

 I'm sorry, what I meant was this.superclass In Prototype's class
 implementation you can see that if you provide a parent-class in prototype's
 Class.Create-Method, that class will be referenced as superclass in the
 class you are creating:

   function create() {
 var parent = null, properties = $A(arguments);
 if (Object.isFunction(properties[0]))
   parent = properties.shift();

 // ...


 klass.superclass = parent;

 // ...

 return klass;
   }


 why not just use this.superclass.method in the subclass?

 --
 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
 prototype-scriptaculous@googlegroups.com.
 To unsubscribe from this group, send email to
 prototype-scriptaculous+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/prototype-scriptaculous?hl=en.


-- 
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 prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



Re: [Proto-Scripty] Why is there a $super-Parameter?

2011-03-18 Thread Luke
Sounds logical ;)

No really, thx :)

-- 
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 prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



Re: [Proto-Scripty] Re: Why is there a $super-Parameter?

2011-03-18 Thread Ryan Gahl
On Fri, Mar 18, 2011 at 9:30 AM, T.J. Crowder t...@crowdersoftware.comwrote:

 Prototype's magical `$super` comes at a marked runtime cost



Just want to point out that the marked runtime cost is only at class
definition time, not instance creation nor method call time. So yeah, the
performance thing is a non issue.

-- 
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 prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



[Proto-Scripty] Re: Why is there a $super-Parameter?

2011-03-18 Thread Luke
Thanks a lot TJ that helps!

-- 
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 prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



[Proto-Scripty] What do you think of this software-architecture?

2011-03-18 Thread Luke
Hi again,

I'm working on a little project that lets users create (very) simple 
websites. On his site the user can add sections (like a text or a big image 
or a video) one below the other. Each section can be edited by clicking a 
link underneath the section. So to structure my code, and give me some 
convenience for later work, I copied and modified prototype's 
class-implementation so that a class created with my implementation can 
[optionally] be passed a DOM-object as parameter, which will be extended 
with a set of methods and properties of the class. That means I can create a 
class for a section and instantiate it passing it a section-DOM-Object. That 
section-object has all functions it needs to have to be edited right 
attached to it.
That allows me to structure my code in a very OOP-like manner, seeing 
DOM-Objects as instances of my classes. Also I can still query the DOM-Tree 
the Prototype way and perform actions on it (like 
$$('.section').first.edit()).
One trap I of course had to work around is name-conflicts, because I'm 
extending with up to 10 methods and properties. I just prefixed my names 
with rb (like $$('.section').first.rbEdit()). It's ugly, but it works.

What do you think of such a structure? Sounds ok? Sounds problematic?

All feedback is very appreciated :)

Lukas

-- 
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 prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



[Proto-Scripty] Re: Why is there a $super-Parameter?

2011-03-18 Thread T.J. Crowder
Hi again,

Sorry for the double-post, somehow I managed to forget to say: My
mechanism isn't just (slightly) more long-winded, it's also more
complex to understand -- it demands more of the programmer. That's its
real downside, not the trivial difference in the length of

method.$super.call(this, arg);

vs.

$super(arg);

To use my mechanism, you have to understand how JavaScript functions
and the `this` keyword work, and it's very easy to make mistakes like
this:

method.$super(arg);

...which fails when the parent class's code tries to use `this`.

So it's about trade-offs. Prototype's mechanism is more newbie-
friendly, and there's real strength in that. My mechanism is
dramatically more efficient, and quite easy to use once you understand
the language a bit better, but not for newbies.

-- T.J. :-)

On Mar 18, 4:01 pm, T.J. Crowder t...@crowdersoftware.com wrote:
 Hi Ryan,

  Just want to point out that the marked runtime cost is only at class
  definition time, not instance creation nor method call time.

 Actually, it's every single time anything calls a method that has the `
 $super` argument (whether the `$super` argument gets used or not).
 Every single call, there are multiple overhead function calls and a
 function *creation*. Here's what happens:

 1. The call to your method is actually to a Prototype wrapper for your
 method
 2. The wrapper calls `Function#bind` (yes, every time)
 3. `bind` calls `Array#slice`, because `bind` handles arguments
 (although it doesn't in this case)
 4. `bind` creates and returns a new function
 5. The wrapper calls its internal `update` function to update the
 arguments
 6. The wrapper calls your actual method via `apply`

 If you actually *use* `$super`, then there are about five extra
 function calls involved before the parent method actually gets called
 (but no new functions get created).

 So the runtime costs are significant, not just at `Class.create` time
 (decompiling every public function in your class to find out whether
 it has a `$super` argument), but also on each and every call to a
 method with a `$super` argument (several additional function calls,
 including creating new function objects).

 Probably *at least* 95% of the time you *don't care*, but still, I was
 pretty shocked when I found out what it was doing, which is what lead
 me to thinking if there was a better way. My mechanism doesn't do any
 function decompilation, doesn't create any functions when your methods
 are called, and introduces *no* extra calls at all [a call to one of
 your methods goes straight to your method, and your call to the parent
 method goes straight to the parent method (unless you use an optional
 helper function)]. But the notation is a bit longer. ;-)

 How much longer? If you use proper named functions, the call can be

     method.$super.call(this, arg);

 ...compared with Prototype's:

     $super(arg);

 If you use anonymous functions (`method: function(arg) { ... }`), then
 it's

     this.method.$super.call(this, arg);

 I don't use anonymous functions, so I get the shorter one.

 -- T.J.  :-)

 On Mar 18, 2:39 pm, Ryan Gahl ryan.g...@gmail.com wrote:







  On Fri, Mar 18, 2011 at 9:30 AM, T.J. Crowder 
  t...@crowdersoftware.comwrote:

   Prototype's magical `$super` comes at a marked runtime cost

  Just want to point out that the marked runtime cost is only at class
  definition time, not instance creation nor method call time. So yeah, the
  performance thing is a non issue.

-- 
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 prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



Re: [Proto-Scripty] Re: Prototype and jQuery

2011-03-18 Thread Joseph O
 Thank you for the reply. I worked on the repairing the code like you
have shown and it does still allows prototype to take control when loaded.
Could I still be missing something simple?

 The three link examples I have shown are to see (1)  jQuery happy and
working, (2) prototype doing it's thing, and (3) to show that the
no.conflict script was still allowing jQuery to work but If pototype loaded
at any point jQuery would stop.

 I reposted the last link to reflect the suggested changes you made.
jQuery still works until prototype is turned back on.

I have put a lot of work into both functions separately not knowing the
conflict would exist. I have come to far to give up and truly could use
further assistant.

On Thu, Mar 17, 2011 at 9:44 AM, T.J. Crowder t...@crowdersoftware.comwrote:

 Hi,

 It's not clear what's wrong from your message or examples.

 Fundamentally, if you want your first link to work when you add
 Prototype to the page, just add the `noConflict` call *immediately*
 after loading the jquery.js file and include the Prototype file, like
 so:

 script src=../Scripts/jquery-1.2.6.js type=text/javascript
 charset=utf-8/script
 scriptjQuery.noConflict();/script
 script src=../lightbox/js/prototype.js type=text/javascript/
 script

 ..and then change your two functions that look like this:

 $(function () {
if ($.browser.msie  $.browser.version  7) return;

// ...
 });

 ...to look like this:

 jQuery(function($) {
if ($.browser.msie  $.browser.version  7) return;

// ...
 });

 Note that I've added `$` as an argument. jQuery passes a reference to
 itself into `ready` handlers, and so you can use a local alias for it
 and not have to change all your code. *Outside* of that `ready`
 handler, `$` will refer to Prototype. (Or just use `jQuery` for jQuery
 throughout the page, but for large scripts it can be convenient to use
 the local alias.)

 Example: http://jsbin.com/uqugo3

 HTH,
 --
 T.J. Crowder
 Independent Software Engineer
 tj / crowder software / com
 www / crowder software / com

 On Mar 16, 6:36 pm, Joseph O joeordo...@gmail.com wrote:
  This has been tossed around the net in many variations yet none have
  worked for me. I have done about ever work around for these two so
  they will like each other and have reached a dead end. I need my image
  fade menu to function with my flash driven lightbox. Please let me
  know if this is something anyone can help with. Here are a few links
  to reference.
 
  This shows the menu working.
 http://fabritechonline.com/content/awning_marquee.html
 
  This shows the Lightbox Working.
 http://fabritechonline.com/content/awning_marquee_test.html
 
  This shows the jQuery / Prototype noConflict script in action.
  (Prototype is disabled)
 http://fabritechonline.com/content/awning_marquee_test_conflict.html
 
  While the script allows jQuery to operate without Prototype loading,
  it still does not function with both.

 --
 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
 prototype-scriptaculous@googlegroups.com.
 To unsubscribe from this group, send email to
 prototype-scriptaculous+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/prototype-scriptaculous?hl=en.



-- 
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 prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



[Proto-Scripty] Re: Prototype and jQuery

2011-03-18 Thread T.J. Crowder
Hi,

That's very strange. I'm afraid the only real thing to do is to walk
through with a debugger. I got far enough to see that for whatever
reason, the jQuery code isn't finding the anchors to add the hover
spans to them, which is why they don't work, but I don't know why not.

It looks like you're using jQuery 1.2.6, which is very, very out of
date. The first thing I'd do is migrate to the latest. Then if the
problem persists, I'd walk through with a debugger.

If you like, you can hire me for a couple of hours to work it out for
you (my rates aren't completely unreasonable). Drop me a note
privately if you want to do that.

Good luck,
--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com


On Mar 18, 6:18 pm, Joseph O joeordo...@gmail.com wrote:
      Thank you for the reply. I worked on the repairing the code like you
 have shown and it does still allows prototype to take control when loaded.
 Could I still be missing something simple?

      The three link examples I have shown are to see (1)  jQuery happy and
 working, (2) prototype doing it's thing, and (3) to show that the
 no.conflict script was still allowing jQuery to work but If pototype loaded
 at any point jQuery would stop.

      I reposted the last link to reflect the suggested changes you made.
 jQuery still works until prototype is turned back on.

     I have put a lot of work into both functions separately not knowing the
 conflict would exist. I have come to far to give up and truly could use
 further assistant.

 On Thu, Mar 17, 2011 at 9:44 AM, T.J. Crowder t...@crowdersoftware.comwrote:







  Hi,

  It's not clear what's wrong from your message or examples.

  Fundamentally, if you want your first link to work when you add
  Prototype to the page, just add the `noConflict` call *immediately*
  after loading the jquery.js file and include the Prototype file, like
  so:

  script src=../Scripts/jquery-1.2.6.js type=text/javascript
  charset=utf-8/script
  scriptjQuery.noConflict();/script
  script src=../lightbox/js/prototype.js type=text/javascript/
  script

  ..and then change your two functions that look like this:

  $(function () {
         if ($.browser.msie  $.browser.version  7) return;

         // ...
  });

  ...to look like this:

  jQuery(function($) {
         if ($.browser.msie  $.browser.version  7) return;

         // ...
  });

  Note that I've added `$` as an argument. jQuery passes a reference to
  itself into `ready` handlers, and so you can use a local alias for it
  and not have to change all your code. *Outside* of that `ready`
  handler, `$` will refer to Prototype. (Or just use `jQuery` for jQuery
  throughout the page, but for large scripts it can be convenient to use
  the local alias.)

  Example:http://jsbin.com/uqugo3

  HTH,
  --
  T.J. Crowder
  Independent Software Engineer
  tj / crowder software / com
  www / crowder software / com

  On Mar 16, 6:36 pm, Joseph O joeordo...@gmail.com wrote:
   This has been tossed around the net in many variations yet none have
   worked for me. I have done about ever work around for these two so
   they will like each other and have reached a dead end. I need my image
   fade menu to function with my flash driven lightbox. Please let me
   know if this is something anyone can help with. Here are a few links
   to reference.

   This shows the menu working.
 http://fabritechonline.com/content/awning_marquee.html

   This shows the Lightbox Working.
 http://fabritechonline.com/content/awning_marquee_test.html

   This shows the jQuery / Prototype noConflict script in action.
   (Prototype is disabled)
 http://fabritechonline.com/content/awning_marquee_test_conflict.html

   While the script allows jQuery to operate without Prototype loading,
   it still does not function with both.

  --
  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
  prototype-scriptaculous@googlegroups.com.
  To unsubscribe from this group, send email to
  prototype-scriptaculous+unsubscr...@googlegroups.com.
  For more options, visit this group at
 http://groups.google.com/group/prototype-scriptaculous?hl=en.

-- 
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 prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.