Re: Fluffy.AJAX is not a constructor. Why not?



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>
.



Relevant Pages

  • Re: All those constructors...
    ... > I have this fairly large class heirarchy, ... creating package visible setXXX() for the init parameters ... creating a public init() method which subclasses use for their constructor ...
    (comp.lang.java.programmer)
  • Re: is such exception handling approach good?
    ... an oracle database in the ctor then what should you do ... of them in constructor; sometimes all of them. ... void AllInOne::RetrieveData ... assert("Cannot init the buffer twice!"); ...
    (microsoft.public.vc.language)
  • Re: is such exception handling approach good?
    ... "Alex Blekhman" wrote: ... of them in constructor; sometimes all of them. ... void AllInOne::RetrieveData ... assert("Cannot init the buffer twice!"); ...
    (microsoft.public.vc.language)
  • Re: trying to call a virtual method from constructor of abstract object
    ... >> I guess it's obvious that the constructor of CObject can't see the ... >> classes definition of init, but I want any derived object to call ... >> it to derived concrete classes is not really a solution. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Error - Declaring static arrays of structs in a class (VC6)
    ... But I think it is also a good style to supply a constructor, and init the ... VC 7.1 is sometimes too forgiving to not-so-good style code. ...
    (microsoft.public.vc.language)