R
RobG
I am playing with a script that will allow columns of a table to be
moved by dragging them left or right. To do this with functions is
fairly straight forward, however after looking at Richard Cornford's
version of Table Highlighter[1] I decided to do it using an object.
Richard's basic code structure is:
var SomeObject = (function()
{
function someFn01(){
// statements
// return something
}
function setOnEvent01(arg1, arg2){
return (function() {
// statements
});
}
return (function(arg1, arg2, argN){
// use someFn01() & setOnEvent01()
})
})();
Are there any particular benefits to this style? It encapsulates all
the functions and variables within a single object, but are there any
others?
Will this expose IE's memory leak problem so that I need to use
Richard's finalizeMe() or something similar?
I intend using this with an onload function that passes a class name
that's used to get references to all the tables that can be re-ordered
with drag 'n drop. It will probably attach mousedown/move/up events to
the tables, get and keep references to all the columns and their
positions and other stuff like indicate which column is being dragged,
where it will go when dropped, etc.
My alternative is to have a constructor that creates an object for each
table to hold data relevant to each table (e.g. references to columns)
and add methods to the object prototype for moving the columns.
Is Richard's way clearly better, or is it just a preference for a
particular coding style?
1.
<URL:http://www.litotes.demon.co.uk/example_scripts/tableHighlighter.html>
moved by dragging them left or right. To do this with functions is
fairly straight forward, however after looking at Richard Cornford's
version of Table Highlighter[1] I decided to do it using an object.
Richard's basic code structure is:
var SomeObject = (function()
{
function someFn01(){
// statements
// return something
}
function setOnEvent01(arg1, arg2){
return (function() {
// statements
});
}
return (function(arg1, arg2, argN){
// use someFn01() & setOnEvent01()
})
})();
Are there any particular benefits to this style? It encapsulates all
the functions and variables within a single object, but are there any
others?
Will this expose IE's memory leak problem so that I need to use
Richard's finalizeMe() or something similar?
I intend using this with an onload function that passes a class name
that's used to get references to all the tables that can be re-ordered
with drag 'n drop. It will probably attach mousedown/move/up events to
the tables, get and keep references to all the columns and their
positions and other stuff like indicate which column is being dragged,
where it will go when dropped, etc.
My alternative is to have a constructor that creates an object for each
table to hold data relevant to each table (e.g. references to columns)
and add methods to the object prototype for moving the columns.
Is Richard's way clearly better, or is it just a preference for a
particular coding style?
1.
<URL:http://www.litotes.demon.co.uk/example_scripts/tableHighlighter.html>