473,804 Members | 3,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does JavaScript support some kind of __Resolve method?

12 New Member
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 1955
gits
5,390 Recognized Expert Moderator Expert
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
12787
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 language = Request.Form ("language"); Response.Write("Edition is type &quot;" + (typeof edition) + "&quot; and value &quot;" + edition + "&quot;<br>");
1
3375
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 completion (the "dot notation") in Dreamweaver MX, like for ex. navigator.plugins.name.indexOf("Flash") Instead of looking in my book reference which objects I am allowed to
2
3489
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 repopulate the 2nd combo based upon the value of the selected item in the first, just like it does in IE.
7
7442
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 = {}; com.unFocus.Namespaces = new function() { this.register = function(namespace) { namespace = namespace.split('.');
17
6453
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 to the panel in VB as follows: pnlAdd.Attributes.Add("onLoad", "SetupScreenLite()") This is basically how we attach all functions in our projects but this is the first time I've worked with onLoad and the first time I've tried to
28
5313
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
29798
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 method 2146827850' Does any one know why this problem occurs?
2
6648
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 Javascript messages, but it also blocks any other dialog box, such as Login dialog, i can't use the silent property. I used http://support.microsoft.com/default.aspx?scid=kb;EN-US;279535 article to suppress the error messages. It works fine until a...
7
6926
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 static member. Any idea ?
0
10593
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10329
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9163
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6858
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4304
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3830
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.