Re: Fluffy.AJAX is not a constructor. Why not?
- From: Thomas 'PointedEars' Lahn <PointedEars@xxxxxx>
- Date: Tue, 01 Jan 2008 18:53:22 +0100
dennis.sprengers@xxxxxxxxx wrote:
To avoid future collisions in the global namespace, I'm transferring
all javascript functions my CMS uses to a global object called
"Fluffy".
That's a good idea if you want to show that you are a script-kiddie ;-)
[...]
Fluffy.Module = function(properties) {
var module = function() {return this.init.apply(this, arguments);};
Fluffy.extend(module, this);
module.prototype = properties;
return module;
A constructor must not return a value different from `undefined'.
}
[...]
Fluffy.AJAX = new Fluffy.Module ({
init : function() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
}
else {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
});
You are calling `Fluffy.Module' as a constructor. A constructor call
returns a reference to the newly constructed object. That object is not a
Function object,
var ajax = new Fluffy.AJAX(); // Fluffy.AJAX is not a constructor
so it cannot be used as a constructor.
You are following the misguided Prototype.js example that requires objects
to have an `init' method in order to be initialized. Use constructor code
for the initialization instead, and use the prototype chain to have one
object inherit properties from another.
PointedEars
--
"Use any version of Microsoft Frontpage to create your site. (This won't
prevent people from viewing your source, but no one will want to steal it.)"
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
.
- Follow-Ups:
- Re: Fluffy.AJAX is not a constructor. Why not?
- From: dennis . sprengers
- Re: Fluffy.AJAX is not a constructor. Why not?
- From: Anthony Levensalor
- Re: Fluffy.AJAX is not a constructor. Why not?
- References:
- Fluffy.AJAX is not a constructor. Why not?
- From: dennis . sprengers
- Fluffy.AJAX is not a constructor. Why not?
- Prev by Date: Fluffy.AJAX is not a constructor. Why not?
- Next by Date: Re: RFD: How To Recognize Bad Javascript Code
- Previous by thread: Fluffy.AJAX is not a constructor. Why not?
- Next by thread: Re: Fluffy.AJAX is not a constructor. Why not?
- Index(es):
Relevant Pages
|
|