473,395 Members | 1,986 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,395 software developers and data experts.

Does JavaScript support some kind of __Resolve method?

I have a dynamic class. I would like to be able to attempt to access properties and methods on that class, and if they do not exist, I want the Class to handle the problem in a specific way, rather than throw an exception.

Thsi needs to be done internally to the class, not with an external "try" clause. In some languages this is known as a __resolve function.

thus

Expand|Select|Wrap|Line Numbers
  1. var foo = new MyClass()
  2.  
  3. function MyClass(){
  4.     this.dog = "woof"
  5.     function __resolve(e) {
  6.         alert("I don't know what a" + e + "is");
  7.     }
  8. }
  9.  
  10. alert(foo.dog) // woof
  11. foo.cat() // I don't know what a cat is
Is this possible?
Apr 2 '08 #1
1 1939
gits
5,390 Expert Mod 4TB
hmmm ... at the moment for a quick shot i would use something like the following for that:

Expand|Select|Wrap|Line Numbers
  1. function OBJ() {
  2.     this.foo = function(s) {
  3.         alert(s);
  4.     };
  5. }
  6.  
  7. OBJ.prototype.f = function(func, params) {
  8.     if (typeof this[func] != 'undefined') {
  9.         this[func].apply(this, params);
  10.     } else {
  11.         alert('i don\'t know what ' + func + ' is.'); 
  12.     }
  13. }
  14.  
  15. var o = new OBJ;
  16.  
  17. o.f('foo', ['test']);
  18.  
that example calls foo like expected and when you try to call:

Expand|Select|Wrap|Line Numbers
  1. o.f('cat', []);
you get it '__resolved' ...

may be that helps?

kind regards

PS: may be that has to be adapted for different things, when trying to call a method (like the example works at the moment) or a simple property or whatever ;)
Apr 4 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Robert Mark Bram | last post by:
Hi All! I have the following code in an asp page whose language tag is: <%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%> // Find request variables. var edition = Request.Form ("edition"); var...
1
by: John | last post by:
Hello, I'm working with Dreamweaver MX and we started to develop our website with Javascript too. However, unlike "Eclipse" for Java developement I don't have the support for Javascript code...
2
by: mark4asp | last post by:
Why does this not work in Mozilla ? <http://homepage.ntlworld.com/mark.pawelek/code/animals.html> The optHabitat_change() event does not fire. What am I doing wrong here? PS: It should...
7
by: Kevin Newman | last post by:
I've been toying with a namespace manager, and wanted to get some input. So what do you think? if (typeof com == 'undefined') var com = {}; if (!com.unFocus) com.unFocus = {}; ...
17
by: B. Chernick | last post by:
I'm trying to create a web page and I need a javascript function to be called on the load of a particular panel. (The panel is hidden during some but not all postbacks.) The function is bound...
28
by: Andre | last post by:
Hi, Does anyone know whether the ECMA, or an other standard document, specifies a maximum for the value that can be pass to the setTimeOut() function in Javascript? Andre
7
by: stellstarin | last post by:
hi all, I have a HTML page with two forms. While trying to add a hidden element in a first form by the default javascript function, the error message 'object does not support this property or...
2
by: ZeeHseez | last post by:
Hi, I have written a webbrowser application in VB .net Framework 1.1. I would like to suppress javascript error messages. However, the silent property of the webbrowser control suppresses the...
7
by: PhilTheGap | last post by:
Hi, I've tried this: <asp:Button ID="Save" runat="server" Text="OK" OnClick="ServerSave" OnClientClick="SaveParam (<% Util.MaxTags %>)" /> but if fails... Util is a C# class, MaxTags a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.