R
Richard A. DeVenezia
foo() generates elements with event handlers that invoke foo function
properties.
Is this an abhorrent or misthought pattern ?
It allows just the one occurence of identifier /foo/ to be changed to
/whatever/ when need arises and everything should still work.
function foo () {
var callee = arguments.callee
if (callee.singleton != undefined)
return callee.singleton
if (this == window)
return new callee(arguments)
installClassFunctions()
callee.singleton = this
return
function installClassFunctions() {
callee.classMethod1 = function () {alert('1')} // global function but
property of foo
callee.classMethod2 = function () {alert('2')}
}
}
foo()
foo.classMethod1() // not normally invoked directly, verifies operation
Even though foo is singleton, the handlers (in question) would have to be
passed a global reference to the singleton instance (if the classMethods
were programmed to be instance of foo properties. (Also, no sense in
prototyping singleton methods)
properties.
Is this an abhorrent or misthought pattern ?
It allows just the one occurence of identifier /foo/ to be changed to
/whatever/ when need arises and everything should still work.
function foo () {
var callee = arguments.callee
if (callee.singleton != undefined)
return callee.singleton
if (this == window)
return new callee(arguments)
installClassFunctions()
callee.singleton = this
return
function installClassFunctions() {
callee.classMethod1 = function () {alert('1')} // global function but
property of foo
callee.classMethod2 = function () {alert('2')}
}
}
foo()
foo.classMethod1() // not normally invoked directly, verifies operation
Even though foo is singleton, the handlers (in question) would have to be
passed a global reference to the singleton instance (if the classMethods
were programmed to be instance of foo properties. (Also, no sense in
prototyping singleton methods)