Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 7th, 2008, 09:54 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
Default attachEvent !?

Hi everyone,

Consider this snippet:

var obj={
  attribute:1,
  documentClicked:function (){
    alert(this.attribute);
  }
}
document.attachEvent('onclick',obj.documentClicked );

When run on IE with page clicks this.attribute is undefined! With Firefox you will face the same issue while using addEventListener instead.
What can I do about it? It's really irritating to put attribute in global scope (window scope) and for some reasons I don't tend to do so at all. By putting onclick in <body> this issue is probably resolved but for some other reasons attachEvent is much better.

Best Regards
Nerssi





Similar Threads
Thread Thread Starter Forum Replies Last Post
attachEvent darkhalf Javascript 3 September 7th, 2006 06:55 PM
about attachEvent mothod of document or window? nerssi Javascript 2 September 16th, 2004 11:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.