/    Sign up×
Community /Pin to ProfileBookmark

How does this thing work?

I can’t figure out how this works.. but it does.

function toString() {
var t = ”;
for (var i in this) {

if (typeof(this[i]==’function’)) continue;
t += i+’ = ‘+this[i]+’n’;
}
return t;
}

BrowserInfo.prototype.toString = toString;
var oBrowser = new BrowserInfo();

*******************************************

Heres what I can figure out. So theres a function called browser info.. and the new toString() function overwrites the default toString function. This new toString function just outputs the entire function in a string. The lines that I dont understand are

for (var i in this) {

if (typeof(this[i]==’function’)) continue;
t += i+’ = ‘+this[i]+’n’;
}

Doesnt var i have to be defined somewhere.. and how can you check whether its equal to ‘function’. Why would they use typeof(this[i]==’function’) instead of just (this[i]==’function’).

Javascript shouldnt be this confusing right? ?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@GollumMay 20.2003 — Methinks the line that says...

if (typeof(this[i]=='function')) continue;



was proably intended to be...



if (typeof(this[i])=='function') continue;



then the output of BrowserInfo.toString() will be all the non-function values of the instance.



typeof(this[i]=='function') will probably evaluate to 'Boolean'



regarding the variable i, it does get defined. Have a look at the for statement...



for (var i in this)
Copy linkTweet thisAlerts:
@eewaldauthorMay 20.2003 — The fog is clearing.

Thanks!
×

Success!

Help @eewald spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...