Я добавляю три кнопки и управляю их одним классом. Но я получаю эту неопределенную ошибку.Неопределенный объект после определения класса
var jQuery = jQuery.noConflict();
jQuery(function(){
var sampTool = new loadToolBar('pageContent');
sampTool.addImgBtn("fontMore","img/plus.png"); // Uncaught TypeError: undefined is not a function
sampTool.addImgBtn("fontLess","img/minus.png");
sampTool.addImgBtn("printPage","img/printer.png");
jQuery('#fontMore').click(function(){
sampTool.zoom('pageContent','+=2px');
});
jQuery('#fontLess').click(function(){
sampTool.zoom('pageContent','-=2px');
});
function loadToolBar(fileBody) // Class definition
{
var toolBar = document.createElement("div");
toolBar.className = "oasys-toolbar";
toolBar.id = "oasys-toolbar";
jQuery(toolBar).insertBefore("#"+fileBody);
}
/*--------------------- Prototypes------------------------*/
loadToolBar.prototype.addImgBtn = function(itemID,itemPath)
{
var newIcon = document.createElement("img");
newIcon.id=itemID;
newIcon.src = itemPath;
newIcon.className = "oasys-toolbar-item oasys-toolbar-btn";
document.getElementById('oasys-toolbar').appendChild(newIcon);
}
loadToolBar.prototype.zoom = function(containerID,size)
{
jQuery("#"+containerID+" *").css("font-size",size);
}
});
Заранее спасибо
Попробуйте переместить определение класса и прототипы вне функции onload. – Xlander
Можете ли вы создать [скрипку] (http://fiddle.jshell.net/) с вашей конкретной проблемой? Это будет легче помочь :) – Kutyel
Я хотел бы указать, что не имеет отношения к фактическим ответам, вы должны называть свои функции-конструкторы с помощью PascalCase - многие инструменты lint будут искать функции PascalCase и попытаться применить некоторые ограничения, как если бы они (например, проверка, если вы вызываете их без новых) – Sacho