473,394 Members | 1,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Error: Object doesn't support this property or method

I'm running the following javascript with no problem in FireFox:

Expand|Select|Wrap|Line Numbers
  1. var multiGallery = {
  2. init: function(options){
  3. this.overlay = new
  4. Element('div').setProperty('id','lbOverlay').injectInside(document.body).addEvent('click',this.close.bind(this));
  5. this.gallery = new
  6. Element('div').setProperty('id','gallery').injectInside(document.body);
  7. this.fx = {
  8. overlay: this.overlay.effect('opacity', {duration: 250}).hide()
  9. }
  10. },
  11.  
In IE7 I get an error that says "Microsoft JScript runtime error:
Object doesn't support this property or method" on each of the "this."
statements.

Anyone have any issues with this and have a fix for it?

Thanks!

Aug 19 '08 #1
6 4345
lo******@gmail.com wrote:
....
Anyone have any issues with this and have a fix for it?

Thanks!
This? This? Really! Who has never had...20 % of my coding time has gone to
thinking, what this means. If somebody could explain this with pictures,
examples, without links to ECMA and without sentences exceeding 15 words, I
would be one of the happiest people on earth.
FAQ might be excellent for those experts, who already know, but anything
with [[scope]], 'Activation object', 'gc', 'execution context' and sentences
with 50 words blur my vision and understanding hopelessly.
Aug 19 '08 #2
optimistx wrote:
If somebody could explain this
You might want to search for an introduction to object oriented
programming. I'll give it a go though. Imagine you have an object and it
has a function in it (which because it's part of an object gets labeled
as a 'method').

var myobj={a:1,b:2,c:3};
myobj.mymethod=function(){return this.a;}

If I call myobj.mymethod() then I will get back the value 1. The 'this'
property in that function refers to the object that it belongs to
basically. You might think why can't you just return myobj.a instead. In
this particular example you can. But take the example below where you can't.

var myfunc=function(){return this.a;}

var myobj1={a:1,b:2,c:3};
var myobj2={a:4,b:5,c:6};
myobj1.mymethod=myfunc;
myobj2.mymethod=myfunc;

If you call myobj1.mymethod() it will return 1.
If you call myobj2.mymethod() it will return 4.

The myfunc function doesn't know which object it will be working on
because it's shared by both objects. The this property is the object
it's being called on.
Aug 19 '08 #3
Stevo wrote:
....
var myfunc=function(){return this.a;}

var myobj1={a:1,b:2,c:3};
var myobj2={a:4,b:5,c:6};
myobj1.mymethod=myfunc;
myobj2.mymethod=myfunc;

If you call myobj1.mymethod() it will return 1.
If you call myobj2.mymethod() it will return 4.

The myfunc function doesn't know which object it will be working on
because it's shared by both objects. The this property is the object
it's being called on.
Thanks for your kind answer. I think I understand your example. In the
meantime I found
http://www.digital-web.com/articles/scope_in_javascript
which explains several other cases. The section 'Complications' contains a
simplified example:

<script type="text/javascript">
function BigComputer(answer) {
this.the_answer = answer;
this.ask_question = function () {
alert(this.the_answer);
}
}

function addhandler() {
var deep_thought = new BigComputer(42),
the_button = document.getElementById('thebutton');

the_button.onclick = deep_thought.ask_question;
}

window.onload = addhandler;
</script>

How is that supposed to work? What is 'this' here and why? Do we get back
the answer '42'? The answer is in the link, but I would be curious to know
how many of the readers could in a minute or two find the correct answer AND
the explanation without looking at the link. (my guess is: 1 or 2 :) )

-----

My two brain cells got twisted like spaghetti with the solution:

Function.prototype.bind = function(obj) {
var method = this,
temp = function() {
return method.apply(obj, arguments);
};

return temp;
}

function addhandler() {
var deep_thought = new BigComputer(42),
the_button = document.getElementById('thebutton');

the_button.onclick = deep_thought.ask_question.bind(deep_thought);
}

If I have to write and read code like this with a speed 60 lines/hour I have
a lot to learn. Good material for learning?


Aug 20 '08 #4
lo******@gmail.com wrote:
I'm running the following javascript with no problem in FireFox:

Expand|Select|Wrap|Line Numbers
  1. var multiGallery = {
  2.     init: function(options){
  3.         this.overlay = new
  4. Element('div').setProperty('id','lbOverlay').injectInside(document.body).addEvent('click',this.close.bind(this));
  5.         this.gallery = new
  6. Element('div').setProperty('id','gallery').injectInside(document.body);
  7.         this.fx = {
  8.             overlay: this.overlay.effect('opacity', {duration: 250}).hide()
  9.         }
  10.     },
  11.  

In IE7 I get an error that says "Microsoft JScript runtime error:
Object doesn't support this property or method" on each of the "this."
statements.

Anyone have any issues with this and have a fix for it?
You are using non-standard objects. Until you tell what these constructor
calls and other calls are going to do, the only and probably best answer
that can be given is: Probably one or more identifiers that you are using
right-hand side of the assignment are not defined, or one or more calls do
not return references to objects which is why the associated property lookup
operation fails.

In any case, bind() smells of Prototype.js or jQuery, whereas both are
generally frowned upon here due to their apparent lack of code quality.

<http://jibbering.com/faq/>
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Aug 20 '08 #5
Try the MooTools user group:
http://groups.google.com/group/mootools-users

I don't see an issue with the code so far.
A larger snippet is needed to further debug your
issue.

Here is a snippet that tries to fill in some of
the gaps in your example code:
http://gist.github.com/6961

- JDD
Aug 24 '08 #6
optimistx wrote:
<snip>
<script type="text/javascript">
function BigComputer(answer) {
this.the_answer = answer;
this.ask_question = function () {
alert(this.the_answer);
}
}

function addhandler() {
var deep_thought = new BigComputer(42),
the_button = document.getElementById('thebutton');

the_button.onclick = deep_thought.ask_question;
}

window.onload = addhandler;
</script>

How is that supposed to work? What is 'this' here and why? Do we
get back the answer '42'? The answer is in the link, but I would
be curious to know how many of the readers could in a minute or
two find the correct answer AND the explanation without looking
at the link. (my guess is: 1 or 2 :) )
You would be wrong. If you look in the group's archives you may see that
issues surrounding the value of - this - in this and similar/related
contexts are quite often the subject of questions to the group, and have
received detailed (and factual) answers from many individual over the
years. Making it certain that the individuals giving those answers
understood the situation, and very likely than the majority of the
individuals reading those answers either already knew or now know the
expected behaviour.

Of course searching the newsgroup for "this" will not be particularly
profitable, but searching for "this keyword" and/or "this operator" will
very likely turn up those answers (strictly - this - is a keyword not an
operator, but strongly insisting on that distinction is a bit too
pedantic).
My two brain cells got twisted like spaghetti with the
solution:

Function.prototype.bind = function(obj) {
var method = this,
temp = function() {
return method.apply(obj, arguments);
};

return temp;
}

function addhandler() {
var deep_thought = new BigComputer(42),
the_button = document.getElementById('thebutton');

the_button.onclick = deep_thought.ask_question.bind(deep_thought);
}

If I have to write and read code like this with a speed 60
lines/hour I have a lot to learn. Good material for learning?
That is not an ideal solution in the context of intrinsic event handlers
because it complicates the process of re-retrieving the reference to -
the_button -, which is often wanted in that sort of context (you either
have to store it as a property of the object (introducing the circular
reference memory leak issue on IE), re-use - getElementById - (and so
hard code or store the identifier in the called method or on the object)
or retrieve it from the event's target (using test-and-branch code to
account for browser differences), when in the intrinsic event listener
call the - this - value would have been a reference to that element).

It also suffers from encouraging a very inefficient style of coding
where the association of the object method and the object is established
just prior to the use of function and re-established for each use (this
is more noticeable with - setTimeout than intrinsic event handlers)
rather than one time only when the object is created. The proposed -
bind - method creates a new function object instance each time it is
called and that is an overhead that may not need to be suffered more
than once.

Richard.

Aug 26 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Matt | last post by:
I tried to display all html control types in the form. But it has run time error "object doesn't support this property or method" on document.write(obj.type); Even I do document.write('hello...
3
by: news.onetel.net.uk | last post by:
I and my friend Karl have spent literally all day trying to find out what is causing my error but we are zapped of any further functionality :) I have a form that adds news records. You select...
2
by: SmittyBroham | last post by:
Hello, I have a function that loops through 2 select lists and records the values of any hi-lighted options a user would have selected. It then sets 2 corresponding "hidden" form elements to the...
0
by: Roman | last post by:
I'm trying to create the form which would allow data entry to the Client table, as well as modification and deletion of existing data rows. For some reason the DataGrid part of functionality stops...
0
by: HKSHK | last post by:
This list compares the error codes used in VB.NET 2003 with those used in VB6. Error Codes: ============ 3: This Error number is obsolete and no longer used. (Formerly: Return without GoSub)...
4
by: Cylix | last post by:
Sample code of the problem: function inputOne() { alert('a'); } <input name="inputOne" id="inputOne" value="Warn" onclick="inputOne()"> The error is the object doesn't support this method.
5
by: John Olbert | last post by:
Subject: Error is Object doesn't support this property or method I am trying to pass a C# string under Vs2005 (Net2) to an Vb6 ActiveX Control. I get the following runtime error-- "Object...
8
by: Kevin Blount | last post by:
I'm tyring to access an object created by using a method from a third party API. The documentation tells me what object should be return, and the properties of that object, but when I try and...
3
by: Peachstone | last post by:
I'm using Windows XP and MS Access 2002. I am trying to write code in VB which is attached to a text control on a form called "Scripture1". I have another text control on the same form called...
21
vikas251074
by: vikas251074 | last post by:
I am getting error while entry in userid field. When user enter his user id, an event is fired immediately and user id is verified using AJAX method. But I am getting error 'Object doesn't support...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.