/    Sign up×
Community /Pin to ProfileBookmark

question about navigator.window

Hi to all,
Hope you all will be fine. Actually i want to ask you people a simple question ?

Is (navigator.window) is same as (“navigator” in window) purporting if i use a conditions like

if ( “navigator” in window )
if ( “createElement” in document )

So i want to ask, these two conditions are same to navigator.window and document.createElement respectively.If yes then why we wrote like this, is it a matter of personal choice only and if no then what is the difference between these two. ?

Another question when we write a function then we use function keyword, then function name like function add() {}, actually i have a code in which someone write function like this
(function (obj){// code})
So i want to ask he did not use any name here so when we write function like above

Thank you ?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KorSep 10.2009 — 
  • 1. [B]navigator[/B] is an object, it is the object representation of the client's browser (or the navigator program used). We may say that navigator is the top level object. As far as I know the [B]navigator[/B] object has 3 objects as his properties: [B]window, MimeType and plugin[/B]


  • [B]window[/B] is the main (the highest level) Javascript object. It is also known as the Global Javascript Object. If so, it is not required to specify the parent object of the window, thus [B]navigator.window[/B] and [B]window[/B] refer the same object, and both references are correct.

    On the other hand, createElement() is a method, not an object. It belongs to the [B]document[/B] object, and the [B]document[/B] object belongs to the [B]window[/B] object. But as [B]window[/B] is the Global Javascript object, usually it is not mentioned as parent. But [B]document[/B] is [I]required[/I] as parent. [B]window[/B] is not.

    In javascript the methods are treated same as the functions (and functions might become methods as well), thus the reference of a function/method is a direct one: your case document.createElement. Don't confound the method/function itself with his [I]reference[/I].

    Thus, the correct conditionals are:
    <i>
    </i>if(navigator.window)
    // or simply
    if(window)

    and
    <i>
    </i>if(document.createElement)


  • 2. I confess I did not understand your question. Are you talking about functions used in closures?
  • ×

    Success!

    Help @Terry56 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.7,
    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,
    )...