Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the prototype object of Location object?

location is the owned property of window and document.

window.hasOwnProperty("location")
true

document.hasOwnProperty("location")
true

But when i tried to compare prototype of location with Location.prototype, i got error that Location is not defined.

Although i can see Location constructor in the Location object.

What is the prototype object of location?

Ideally we should be able to see Location.prototype and methods on it like assign and other two.

Chrome bug? enter image description here

like image 812
P K Avatar asked Jan 04 '13 15:01

P K


2 Answers

A prototype may not be visible, even if it's listed.

Try this :

​var a = (function(){ // this is a closure protecting A
    var A = function(b){
        this.b = b;
    }
    return new A('test');
})();
console.log(a); // logs ▸A
console.log(A); // error, as A isn't defined

There is no reason for the browser to make Location visible. And certainly no reason for it to clutter the global namespace.

like image 92
Denys Séguret Avatar answered Nov 11 '22 21:11

Denys Séguret


w3 calls the location object an "interface", see http://www.w3.org/html/wg/drafts/html/master/browsers.html#location so it is propably no goot idea to extend the prototype of it.

Why do you want to extend the prototype of Location? Is there a better way to solve your origin problem?

like image 44
afx Avatar answered Nov 11 '22 23:11

afx