这是我的JavaScript代码。
Html5Template_300x250 = function(config) {
this.config = config;
var self = this;
this.init();
Html5Template_300x250.prototype = {
// Function That Creates Element Var
d: function(id) {
return document.getElementById(id);
},
// Initialize DCO HTML5 template
init: function() {
alert("test1");
this.startAd();
},
startAd: function() {
alert("test2");
}
};
}
我正在创建一个HTML文件,可以使用以下方法:
var sr_Config = {
bgColor:'#fff',
ctaText:'Learn More',
border: 'true'
};
var Html5Template = new Html5Template_300x250(sr_Config);
但我遇到了错误
TypeError: this.init不是一个函数this.init();
我不确定这里出了什么问题,我也尝试了self.init(),但仍然无法工作。
我是JavaScript的新手,正在学习JavaScript中的面向对象编程,如果有人能告诉我在这里做错了什么,那就太好了。先谢谢了。