9three Posted February 11, 2010 Share Posted February 11, 2010 Hey, I'm trying to learn the ways of OO in JS. I'm trying to use prototype but it's not working right. The error message I get is "this.makeSortable is not a function" function tableSort(id) { this.tbl = document.getElementById(id); if (this.tbl && this.tbl.nodeName == 'TABLE') this.makeSortable(); } tableSort.prototype.makeSortable = function () { var headings = this.tbl.tHead.rows[0].cells; alert(headings); } Everything seems correct. So this is what I did: <a href="#" onclick="tableSort('sales'); return false;">Click</a> <table id="sales"></table> Link to comment https://forums.phpfreaks.com/topic/191723-understanding-prototype-a-little-better/ Share on other sites More sharing options...
yozyk Posted February 11, 2010 Share Posted February 11, 2010 inside tableSort this points on global scope (object window) Link to comment https://forums.phpfreaks.com/topic/191723-understanding-prototype-a-little-better/#findComment-1010629 Share on other sites More sharing options...
9three Posted February 11, 2010 Author Share Posted February 11, 2010 Not sure what you mean. Link to comment https://forums.phpfreaks.com/topic/191723-understanding-prototype-a-little-better/#findComment-1010740 Share on other sites More sharing options...
yozyk Posted February 11, 2010 Share Posted February 11, 2010 <a href="#" onclick="new tableSort('sales'); return false;">Click</a> Link to comment https://forums.phpfreaks.com/topic/191723-understanding-prototype-a-little-better/#findComment-1010770 Share on other sites More sharing options...
9three Posted February 11, 2010 Author Share Posted February 11, 2010 Gotcha, thanks. Link to comment https://forums.phpfreaks.com/topic/191723-understanding-prototype-a-little-better/#findComment-1010774 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.