Проблема с return this
Пытаюсь построить конструкцию подобную jQuery. Но возникли проблемы..
function $(data) { return new func(data); } function func(data) { this.obj = document.getElementById(data); return this; } func.prototype.drag = function(data) { var drag = this.obj; drag.onmousedown = function(e) { var self = this.obj; e = $().getEvent(e); drag.style.position = 'absolute'; var coords = $().getCoords(self); var shiftX = e.pageX - coords.left; var shiftY = e.pageY - coords.top; document.onmousemove = function(e) { drag.style.left = e.pageX - shiftX + 'px'; drag.style.top = e.pageY - shiftY + 'px'; }; document.onmouseup = function() { drag.style.cursor = 'default'; document.onmousemove = document.onmouseup = document.ondragstart = document.body.onselectstart = null; }; }; drag.ondragstart = function() { return false; }; } Обращаюсь так: $('el').drag(); Всё работает, но мне хотелось бы сделать так, чтобы $('el') возвращало объект этого элемента. Пишу так: function func(data) { this.obj = document.getElementById(data); return this.obj; } И после этого идёт полный фэйл(( К примеру, лиса негодует и визжит: " mj("el").drag is not a function ". Ребят, как исправить проблему? |
nasqad,
нее. Это не то. //ну да ладно, задачу решил обходными путями)) |
Часовой пояс GMT +3, время: 19:46. |