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> Quote Link to comment 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) Quote Link to comment Share on other sites More sharing options...
9three Posted February 11, 2010 Author Share Posted February 11, 2010 Not sure what you mean. Quote Link to comment 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> Quote Link to comment Share on other sites More sharing options...
9three Posted February 11, 2010 Author Share Posted February 11, 2010 Gotcha, thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.