473,654 Members | 3,253 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getObjectName v0.1

VK
This script allows you to get the object name literal as string.
It works as long as caller property is supported and as long as a call
chain is presented (thus one could backtrace to the holder of the
literal).

A need of such script is more than questionnable. I guess these
literals just got me of being too dazzling: you see them, you can touch
them, but you cannot get their damn name despite it's just in front of
you. :-)
<html>
<head>
<title>Object name</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script>
var foo = new Object();
var bar = foo;

function test(obj) {
alert(getObject Name(obj));
}

function getObjectName(o bj) {
var thisCaller = getObjectName.c aller;
// Go through the call chain to find
// the true name holder:
while ((thisCaller)&& (thisCaller.cal ler)) {
thisCaller = thisCaller.call er;
}
if (thisCaller) {
var re = /(\(\s*)(.+)(\s* \))/;
var f = thisCaller.toSt ring();
re.exec(f);
return RegExp.$2;
}
else {
// caller property is not supported
// or the call chain is broken
return 'undefined';
}
}
</script>
</head>

<body bgcolor="#FFFFF F" onload="test(fo o)">

</body>
</html>

Jul 25 '05 #1
3 2556
>A need of such script is more than questionnable

It is useful if you want to serialise your data.

Assuming I create some constructor object for a particular kind of
data:-

function myData()
{

}

If I want to serialise this properly, I also need to know the name of
the constructor (myData), so that when I unserialise I know which
constructor to call.

A serialised form could be

[
[
"myData",
{
"property":"val ue"
"property":"val ue"
"property":"val ue"
}
],
[
"myData",
{
"property":"val ue"
"property":"val ue"
"property":"val ue"
}
]
]

When unserialising I can then use:-

var oInstance=new window[sConstructor]();
oInstance.prope rty=value;
etc

Jul 26 '05 #2
Baconbutty wrote:
A need of such script is more than questionnable
It is useful if you want to serialise your data.

Assuming I create some constructor object for a particular kind of
data:-

function myData()
{

}


Consider adding:

myData.prototyp e = {
property1: value1,
property2: value2,
constructor: myData
}
If I want to serialise this properly, I also need to know the name of
the constructor (myData), so that when I unserialise I know which
constructor to call.

A serialised form could be
[
{
property1: value1,
property2: value2,
constructor: myData
}
]

[snip]
When unserialising I can then use:-

var oInstance=new window[sConstructor]();
oInstance.prope rty=value;
etc


or:
// assuming you've parsed it into an actual var oData
var oInstance = new oData[0].constructor( oData[0] );
Write your constructors to accept objects that are based on what
they're constructing, using the properties of the passed object to
override defaults in the prototype/constructor.

Of course, doing it this way means you're also serializing actual code,
the benefits, drawbacks, and adviseability of which will vary.

Just something to think about.

Jul 27 '05 #3
Thank you Christohper.

They are some interesting points to consider.

I will experiment with them.

I have been looking at different ways of serialising data, simply
because my only coding skills are in Javascript, so as well as for web
pages, I use DHTML to write on-the-fly mini browser-applications for
use in my work (e.g. I have written a small personal time recording
application) which require data to be serialised.

Thanks again.

Jul 27 '05 #4

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

Similar topics

5
1985
by: Greg Swindle | last post by:
Hello, I have a question about how prototyping relates to variables and their scope. Given the following code: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var ParentObject = function() { var objectName = "ParentObject";
17
31657
by: warteschlange | last post by:
is there a way to find out the object/function name from inside object/function. function coffee(){ alert(this.someHowGetMyNameFuncOrVar); => should give me 'coffee' } var milk = new coffee(); => should give me 'milk'
4
4911
by: Robert Skidmore | last post by:
I made this javascript to help me debug some javascript one time and I have just been adding to it over the years. It is IE specific (sure it would not be to hard to change that). It is not ever meant to be rolled to a production environment. What it does: After you displaying the debug window (see tip 1) you can move your mouse over any element on the page and the window will populate with all the properties, events, and objects (yea,...
1
3372
by: vector | last post by:
There's got to be a better way to do this. In this sample code, I've created a class in a namespace, and a class inside of a class. On calling .ToString() for those two classes, I see different output: name of Class1 is: ConsoleApplication1.Class1 name of Class2 is: ConsoleApplication1.CMain+Class2 I'm not interested in the hierarchical name of the class. All I
2
1331
by: Ken Varn | last post by:
Not sure if this is possible or not or if there is a better method for doing this that I am not seeing. Anyhow, is there anyway to get the declared name of an object that is passed to a function? See below: public class TestClass { public String GetObjectName(Object O) { return // Want to be able to determine that O's declared name is "MyString" as passed by TestFunc()
70
27405
by: jojoba | last post by:
Hello! Does anyone know how to find the name of a python data type. Conside a dictionary: Banana = {} Then, how do i ask python for a string representing the name of the above dictionary (i.e. 'Banana')?
28
7199
by: davinski | last post by:
So thanks to another member here I got my view sorted out :D but now that I've begun to write my stored proc I've ran into another problem! Basically, my stored proc takes about 30 variables and I want to build a WHERE CLAUSE constraint upon these variables. Only thing is, I would like to check the variable values before adding them to the WHERE clause and if the value of the variable is null or "" then I would like to omit the constraint...
0
8816
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
8709
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
8494
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
8596
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
7309
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
5627
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
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1924
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1597
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.