Показать сообщение отдельно
  #1 (permalink)  
Старый 19.04.2012, 21:05
Профессор
Отправить личное сообщение для (Sandr) Посмотреть профиль Найти все сообщения от (Sandr)
 
Регистрация: 14.10.2010
Сообщений: 376

Проблемы с методами
Приветствую!

Есть код:

function j(data) {
  //return new Operation(data); 
  if(!data.oper) {
    data.oper = new Operation(data);
  }
  return data.oper;
  
}
function Operation(data) {
  if(typeof(data) == 'object')
    this.obj = data;
  else
    this.obj = document.getElementById(data);
  this.stackClick = [];
  return this;
}
Operation.prototype = {
  click: function(func) {
	  var self = this;
	  this.stackClick.push(func);
	  if(!this.obj.onclick) this.obj.onclick = function() { self.startClick(); }
  },
  startClick: function() {
    for(var i = 0; i <= this.stackClick.length-1; i++) {
      this.stackClick[i]();
    }
  },
  spoiler: function(data) {
    var cObj = this.obj;
    var sObj = j(data['change']).obj;
    j(cObj).click(function() {
      sObj.style.display == 'none' ? sObj.style.display = 'block' : sObj.style.display = 'none';
    });
  }
}
window.onload = function() {
  j(document).click(function() { document.getElementById('q').innerHTML = Math.floor( Math.random() * (10 - 1 + 1) ) + 1; });  
  j(document).click(function() { document.getElementById('w').innerHTML = Math.floor( Math.random() * (10 - 1 + 1) ) + 1; });
  j('res').spoiler({change: 'q'});   
}


При запуске хром выдаёт следующее: "Uncaught TypeError: Cannot call method 'spoiler' of undefined".
Подскажите пожалуйста, в чём ошибка? Чем ему не нравится spoiler?

Последний раз редактировалось (Sandr), 19.04.2012 в 21:54.
Ответить с цитированием