Bind exists in ES5 https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind and it has compatibility code there, or you can use Sergio's code, or jQuery.proxy or the (probably) dozen other ways of doing it. ------------------------ Gary Katsevman Computer Science Undergraduate Northeastern University gkatsev.com
On Thu, Mar 3, 2011 at 14:27, Kyle <blackb...@gmail.com> wrote: > jQuery also has done similar with the jQuery.proxy function. > > http://api.jquery.com/jQuery.proxy/ > > var Dialog = function() { > this.width = 400; > this.setWidth = $.proxy(function(newWidth) { > this.width = newWidth; > }, this); > } > > -Kyle Brown > > On Thu, Mar 3, 2011 at 11:08 AM, Jarek Foksa <ja...@kiwi-themes.com> wrote: >> >> Hi, >> >> When writing constructor functions it's very convenient to create "var >> self = this" assignment so that we could easily access other >> properties and methods even if default context has changed, for >> example: >> >> var Dialog = function() { >> var self = this; >> this.width = 400; >> this.setWidth = function(newWidth) { >> self.width = newWidth; >> } >> } >> >> But is it really a good idea to use "self" variable name for this >> purpose? It seems to be already assigned to window object by default, >> so I guess redefining it might break some third-party code. >> >> What other names would you recommend? Is there some other convention? >> >> -- >> To view archived discussions from the original JSMentors Mailman list: >> http://www.mail-archive.com/jsmentors@jsmentors.com/ >> >> To search via a non-Google archive, visit here: >> http://www.mail-archive.com/jsmentors@googlegroups.com/ >> >> To unsubscribe from this group, send email to >> jsmentors+unsubscr...@googlegroups.com > > -- > To view archived discussions from the original JSMentors Mailman list: > http://www.mail-archive.com/jsmentors@jsmentors.com/ > > To search via a non-Google archive, visit here: > http://www.mail-archive.com/jsmentors@googlegroups.com/ > > To unsubscribe from this group, send email to > jsmentors+unsubscr...@googlegroups.com > -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/jsmentors@jsmentors.com/ To search via a non-Google archive, visit here: http://www.mail-archive.com/jsmentors@googlegroups.com/ To unsubscribe from this group, send email to jsmentors+unsubscr...@googlegroups.com