f



Can't find 'Prototype' syntax in JavaScript Bible'

'JavaScript Bible' v6 by Danny Goodman doesn't seem to describe the
snytax used in Prototype.js.  Namely, I could not find discussion of
'Object.extend' and the ':' feature (e.g., 'toColorPart:'), as in:

Object.extend(Number.prototype, {
  toColorPart: function() {
    var digits = this.toString(16);
    if (this < 16) return '0' + digits;
    return digits;
  },

Similarly (or perhaps, not so similar), what this is about:

var Try = {
  these: function() {
   ....
  }
}

Can someone please tell me where to find this in the book, or if it's
not covered, where I can read up on this syntax.

Thanks
- Paul
0
SmallPaul
1/22/2008 11:04:32 PM
comp.lang.javascript 38370 articles. 1 followers. javascript4 (1315) is leader. Post Follow

3 Replies
568 Views

Similar Articles

[PageSpeed] 10

On Jan 22, 6:04=A0pm, SmallPaul <VerySmallP...@gmail.com> wrote:
> 'JavaScript Bible' v6 by Danny Goodman doesn't seem to describe the
> snytax used in Prototype.js. =A0Namely, I could not find discussion of

Why would it?  Prototype is a library.

> 'Object.extend' and the ':' feature (e.g., 'toColorPart:'), as in:

The ": feature" is part of the object literal syntax.  That should be
in any "JavaScript Bible."

The Object.extend method is silly.  It was clearly dreamed up by a
person who didn't understand the inheritance features of the language.

>
> Object.extend(Number.prototype, {
> =A0 toColorPart: function() {
> =A0 =A0 var digits =3D this.toString(16);
> =A0 =A0 if (this < 16) return '0' + digits;
> =A0 =A0 return digits;
> =A0 },
>
> Similarly (or perhaps, not so similar), what this is about:
>
> var Try =3D {
> =A0 these: function() {
> =A0 =A0....
> =A0 }
>
> }
>

I am not sure.  It looks like a wrapper for try/catch.

> Can someone please tell me where to find this in the book, or if it's
> not covered, where I can read up on this syntax.

Try a Prototype newsgroup if you feel you really want to use that
thing.  You are really better off without it.
0
David
1/22/2008 11:13:53 PM
SmallPaul meinte:
> 'JavaScript Bible' v6 by Danny Goodman doesn't seem to describe the
> snytax used in Prototype.js.  Namely, I could not find discussion of
> 'Object.extend' and the ':' feature (e.g., 'toColorPart:'), as in:
> 
> Object.extend(Number.prototype, {
>   toColorPart: function() {
>     var digits = this.toString(16);
>     if (this < 16) return '0' + digits;
>     return digits;
>   },
> 
> Similarly (or perhaps, not so similar), what this is about:
> 
> var Try = {
>   these: function() {
>    ....
>   }
> }
> 
> Can someone please tell me where to find this in the book, or if it's
> not covered, where I can read up on this syntax.

That's JS object notation. There are plenty of ressources on that on the 
web. One randomly picked:
<http://msdn2.microsoft.com/en-us/library/bb299886.aspx#intro_to_json_topic2>

Gregor


-- 
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com  ::: meine JS-Spielwiese
http://www.image2d.com       ::: Bildagentur f�r den alpinen Raum
0
Gregor
1/22/2008 11:40:26 PM
SmallPaul wrote:
> 'JavaScript Bible' v6 by Danny Goodman doesn't seem to describe the
> snytax used in Prototype.js.

That's too bad because both have been written by people who don't know
J(ava)Script.


PointedEars
-- 
var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
)  // Plone, register_function.js:16
0
Thomas
1/23/2008 1:04:45 AM
Reply: