JavaScript 使用類的時候,一個很奇怪的問題
由于小弟知識有限,在使用JavaScript 封裝類的時候遇到了下面奇怪的問題。
是否在類中不能使用 Object 類型傳遞呢?
因為經過測試,this.path 是一個普通變量是可以正常使用的。
MK-TIANYI
var AXML = Class.create();
AXML.prototype = {
initialize : function(path){
this.xmlDom = new ActiveXObject("Msxml2.DOMDocument");
this.xmlDom.load(path);
//this.xmlDom = xmlObject;
alert(this.xmlDom); // 可以輸出正確的變量 Object
this.path = path;
},
getHomePage : function(){
alert(this.xmlDom); //變量變成了沒定義
alert(this.path); // 可以輸出正確的變量
}
};
AXML.prototype = {
initialize : function(path){
this.xmlDom = new ActiveXObject("Msxml2.DOMDocument");
this.xmlDom.load(path);
//this.xmlDom = xmlObject;
alert(this.xmlDom); // 可以輸出正確的變量 Object
this.path = path;
},
getHomePage : function(){
alert(this.xmlDom); //變量變成了沒定義
alert(this.path); // 可以輸出正確的變量
}
};
是否在類中不能使用 Object 類型傳遞呢?
因為經過測試,this.path 是一個普通變量是可以正常使用的。
MK-TIANYI
posted on 2008-05-30 09:02 天一 閱讀(1359) 評論(4) 編輯 收藏 所屬分類: JavaScript