transmat
07-10-2003, 05:01 PM
I have been going over youngpup's (www.youngpup.net > Components > ypSlideOutMenus) slide out menu script and there are 2 prototype properties like so:
ypSlideOutMenu.prototype.onactivate = function() { }
ypSlideOutMenu.prototype.ondeactivate = function() { }
which look like an adaptation of Dan Steinman's onSlide and onSlideEnd Handlers.
I almost get what DS is talking about (http://www.dansteinman.com/dynduo/en/dynlayer-slide.html bottom of page).
But with YP's I can't quite grasp what those do. Is it nothing? does it capture the event and do something? Or is it for customization?
anybody have experience with such stuff?
thanks
Charles taught me about this before. Perhaps this will help you:
Originally posted by Charles
<script type="text/javascript">
<!--
String.prototype.toInitialUpperCase = function () {
var a = this.split('');
a[0] = a[0].toUpperCase();
return a.join('');
}
String.prototype.toTitle = function () {
var a = this.split(/\b/);
for (j=0;j<a.length;j++) {a[j] = a[j].toInitialUpperCase()};
return a.join('');
}
alert('Phiv hatecra, scrar muvali pa depivius imedr.'.toTitle())
// -->
</script>
JavaScript is an object oriented language, though it has some short cuts that allow programmers treat it otherwise. An object is complex data type that can hold any number of other pieces of data. And these other pieces of data can be variables, functions or other objects. Except that functions of an object are known as methods and variables known as properties. And the two are interchangable. You can assign a method to a property. That's why you need the parentheses to call a method. Pretty much all objects are properties of other objects, forming a tree structure not unlike the directory on your hard drive and with window objects as the roots.
JavaScript also has some primitive data types, like arrays and strings but they get converted to Array and String objects as needed. Note the capitalization convention. Class names start with capital letters. Each particular String object is a member of the String class and it inherits methods of that class. Consider
'Enegon pisiscrotis, acequor cisit ra alefore pletoher.'.toUpperCase();
That creates a String object and it calls one of its methods, passing no parameters to it. Now we can give this object it's own method:
s = new String('Enegon pisiscrotis, acequor cisit ra alefore pletoher.');
s.reverse = function () {return this.split('').reverse().join('')};
alert(s.reverse());
Or we can give the entire class the method:
String.protype.reverse = function () {return this.split('').reverse().join('')};
alert('Enegon pisiscrotis, acequor cisit ra alefore pletoher.'.reverse());
We could also have given the String class a method that isn't inherited by the members of that class:
String.reverse = function () {return 'esrever'};
alert(String.reverse());
The construction:
function reverse () {}
is shorthand for
window.reverse();
Now, the String class defines a number of useful methods, among them toUpperCase. It makes sense, in a twisted way perhaps, to have our toTitle method work the same way. We really don't want to make a method of a window object that takes a string as a parameter when we can simply make a method that all Strings will inherit.
[J]ona