Or "if (Prototype) { ... }" ?
--
T.J. Crowder
tj / crowder software / com
On Jun 6, 10:12 pm, kangax <[EMAIL PROTECTED]> wrote:
> typeof unfortunately returns "object" when applied to null
> typeof null; // "object"
>
> A safer way is to test for undefined:
>
> if (typeof Prototype != 'undefined') {
> ...
>
> }
>
> - kangax
>
> On Jun 6, 4:35 pm, nlloyds <[EMAIL PROTECTED]> wrote:
>
> > On Jun 4, 1:50 pm, sheps-ii <[EMAIL PROTECTED]> wrote:
>
> > > Thank you, that's fantastic. I love how prototype helps true
> > > modularity into content(server side)->structure (html)->behaviour
> > > (js). Cheers!
>
> > To take it a step further, I usually encapsulate everything in a class
> > or namespace. So, the bottom of the html looks like this:
>
> > <script type="text/javascript" src="prototype.js"></script>
> > <script type="text/javascript" src="mysite.js"></script>
> > </body>
> > </html>
>
> > Then the mysite.js:
>
> > if (typeof Prototype == "object") { // only load if Prototype is
> > present
> > var MySite = Class.create({
> > initialize : function () {
> > ... // stuff to do on page load
>
> > this.addObservers();
> > },
>
> > // Add additional event handlers here
> > addObservers : function () {
> > ...
> > },
>
> > ...
>
> > });
> > document.observe("dom:loaded", function () { new MySite() });
>
> > }
>
> > I don't know if that's the best way to do things, but It works well
> > for me. YMMV
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---