Richard said:
http://www.chunkysoup.net/advanced/oojavascript1/finishedgallery.html
This is by far the most unique galleries I've seen yet.
After seeing this, I know my idea can come together.
You're polluting the global namespace by defining your "JavaScript
object" "methods" outside the "class".
// object constructor
function csnPhotoObject(thumbID,thumbOffURI,thumbOnURI,fullID,fullURI) {
// code snipped
// attach object's methods
this.showThumb = csnPhotoObjectShowThumb;
this.hideThumb = csnPhotoObjectHideThumb;
this.showFull = csnPhotoObjectShowFull;
}
// define object's methods
// ALL THESE METHOD NAMES ARE IN THE GLOBAL
// NAMESPACE AND COULD BE OVERWRITTEN BY
// ANOTHER LIBRARY OF CODE. THEY CAN ALSO
// BE CALLED DIRECTLY, WHERE REFERENCES TO
// -this- IN THEM WOULD REFER TO THE GLOBAL
// OBJECT, PROBABLY NOT WHAT YOU INTENDED
function csnPhotoObjectShowThumb() { /* code snipped */ }
function csnPhotoObjectHideThumb() { /* code snipped */ }
function csnPhotoObjectShowFull() { /* code snipped */ }
Perhaps what you wanted is:
function MyObject(...params...) {
var param1 = param1;
var param2 = param2;
this.method1 = function() { /* code */ }
this.method2 = function() { /* code */ }
}
--- OR ---
function MyObject(...params...) {
this.param1 = param1;
this.param2 = param2;
}
MyObject.prototype.method1 = function() { /* code */ }
MyObject.prototype.method2 = function() { /* code */ }
At least with the above examples, I've encapsulated the "methods" that
belong to the "class" within the "class" and reduced polluting the
global namespace with all those functions. It also makes it much harder
for another library of code or JavaScript author to trample all over my
code.