Looks like you can't extend ActiveXObject.
Have you considered using a "wrapper" or "factory" approach?
function createDoc(methods) {
return Object.extend(new ActiveXObject("Microsoft.XMLDOM"),
methods);
}
- kangax
On May 15, 5:04 pm, donundeen <[EMAIL PROTECTED]> wrote:
> Hi, I'm having trouble extending instances of ActiveXObject using
> Object.extend in IE.
> I'm getting the message: "Object doesn't support this property or
> method"
> Here's my sample code, to show working and non-working examples:
>
> var newDef = {
> foo : function(){
> return "hey there";
> }
>
> };
>
> alert("starting");
> var string;
> var doc;
> var obj;
> try{
> if(typeof ActiveXObject == "undefined"){
> doc = document.implementation.createDocument("", "", null);
> }else{
> doc = new ActiveXObject("Microsoft.XMLDOM");
>
> }
> Object.extend(doc, newDef);
> alert("1 object Extended");
> // FF: this message is displayed}catch(e){
>
> alert("2 " + e.description);
> // IE : this message is displayed.}
>
> if(typeof ActiveXObject != "undefined"){
> try{
> Object.extend(ActiveXObject.prototype, newDef);
> alert("3 extended ActiveXObject.prototype");
> // IE : this message is displayed
> doc = new ActiveXObject("Microsoft.XMLDOM");
> try{
> var text = doc.foo();
> alert("4 " + text);
>
> }catch(e){
> alert("5 " + e.description);
> // IE : this message is displayed
> }
> }catch(e){
> alert("6 " + e.description);
> }}
>
> try{
> obj = new Object();
>
> Object.extend(obj, newDef);
> alert("7 extended string");
> // IE & FF : this message is displayed.}catch(e){
>
> alert("8 " + e.description);}
>
> try{
> alert("9 " + obj.foo());
> // IE & FF: this message is displayed.}catch(e){
>
> alert("10 " + e.description);
>
> }
>
> try{
> string = "hey";
> Object.extend(String.prototype, newDef);
> alert("11 " + string.foo());
> // IE & FF : this message is displayed.}catch(e){
>
> alert("12 " + e.description);
>
> }
>
> the problem areas for me are messages 2 and 5. Is there a reason I
> can't extend the ActiveXObject instance, or if, when I extend the
> prototype, I can't actually use the methods defined?
>
> I'm able to extend the document instance firefox creates, and I was
> really hoping to use the same approach in IE. Is there a workaround?
>
> Sorry if maybe I've posted this twice...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---