HighDots Forums  

Re: Size of an object

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: Size of an object in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
slebetman
 
Posts: n/a

Default Re: Size of an object - 06-22-2008 , 09:30 PM






On Jun 20, 6:24 pm, Henry <rcornf... (AT) raindrop (DOT) co.uk> wrote:
Quote:
On Jun 20, 9:21 am, slebetman <slebet... (AT) gmail (DOT) com> wrote:

On Jun 20, 2:29 am, VK <schools_r... (AT) yahoo (DOT) com> wrote:
snip
Of course this piece of knowledge is useless for open
Web-wide solutions.

Or steal the idea and implement your own Dictionary:

But maybe best to steal one written by someone who understands the
issues.

function Dict (obj) {
var that = this;
var internalHash = {};
var internalCount = 0;

if (obj) {
snip
that.count = function () {
return internalCount;
}
}

var d = new Dict({
this : 1,

^^^^
This, the code and the keyword in this context, is a syntax error.
Sorry, should have tested before posting
should have been:

var d = new Dict({
'this' : 1,
that : 2
});

Quote:
Now add:-

d.remove('constructor');
d.remove('toString');
d.remove('valueOf');
d.remove('isPrototypeOf');

alert(d.count()); // -1

- and observe a significant flaw in that implementaion.
Yeah, forgot about that. The remove method should be:

that.remove = function (key) {
if (internalHash.hasOwnProperty(key)) {
internalCount--;
delete internalHash[key];
}
}


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.