markifornia 3 Posted October 25, 2012 Report Share Posted October 25, 2012 var U = { $: function(id) { 'use strict'; if(typeof id = 'string') { return document.getElementById(id); } // end of typeof } // end of $() function } // end U object This is a rather simple question. The text says the $() function is a property of U, isn't this function technically a method and not a property? Thanks, Mark Quote Link to post Share on other sites
HartleySan 826 Posted October 25, 2012 Report Share Posted October 25, 2012 Yes. There are many different ways to refer to "things" attached to objects. Some people call everything attached to an object a property, and other people differentiate between properties and methods. At the end of the day, the behavior is the same, so it doesn't matter, but I agree that it's more explicit to call $ a method, not a property. "A rose by any other name ...," I guess. Quote Link to post Share on other sites
Edward 108 Posted October 25, 2012 Report Share Posted October 25, 2012 Method Quote Link to post Share on other sites
Antonio Conte 426 Posted October 26, 2012 Report Share Posted October 26, 2012 The function/method is a property of the object because the method is really only an object assigned to a property. When you call the property, the method is invoked. Everything, even functions, are objects in Javascript. For clarity, you should call them methods, though they technically are objects assigned to properties. Because the act like methods, they should be called that though. Quote Link to post Share on other sites
Edward 108 Posted October 26, 2012 Report Share Posted October 26, 2012 Window is a property of navigator and so document is a property of window. That's what you are saying? But all these properties are methods in objects? Quote Link to post Share on other sites
HartleySan 826 Posted October 26, 2012 Report Share Posted October 26, 2012 window is the master object of Javascript. Both navigator and document are properties of the window object, even though navigator and document are both objects themselves. In other words, an object attached to an object is a property of the parent object. Another way to put it: Anything that's not a function attached to an object is a property. Only functions attached to objects can be methods (even though some people also call those properties too). Quote Link to post Share on other sites
Edward 108 Posted October 26, 2012 Report Share Posted October 26, 2012 Yeah thats what i was meaning. But hey i read oine that navigator was the highest level of object and window was below followed by document. Quote Link to post Share on other sites
HartleySan 826 Posted October 26, 2012 Report Share Posted October 26, 2012 Hmmm... I don't think that's right. I only hesitate to say that with 100% certainty because there are some sights out there that claim the navigator object is above the window object, but that makes no sense since window.navigator is used. I'm pretty sure the following is right: http://www.irt.org/a...s169/object.gif Actually, after testing things, I'm certain that the window object is the top object and the navigator is in the window object. Run the following JS code: for (var prop in window) { document.body.innerHTML += prop + '<br>'; } You'll see navigator in the list. Then run this code: for (var prop in navigator) { document.body.innerHTML += prop + '<br>'; } No window object. That settles that. Quote Link to post Share on other sites
Edward 108 Posted October 26, 2012 Report Share Posted October 26, 2012 Well whether is or not it does really matter as common properties can be accessed via document or window and thats all we need. Quote Link to post Share on other sites
HartleySan 826 Posted October 26, 2012 Report Share Posted October 26, 2012 Well, it's a matter of correctness, and you were questioning it, which is why I investigated it. Anyway, on with life! Quote Link to post Share on other sites
Edward 108 Posted October 26, 2012 Report Share Posted October 26, 2012 Hopefully someone will give us some more insight into this. Correctness is something that lacks in my country, that is why my attitude is like this i see things differently. Quote Link to post Share on other sites
Edward 108 Posted October 26, 2012 Report Share Posted October 26, 2012 Ill check that code tomorrow seems to be okay. Quote Link to post Share on other sites
HartleySan 826 Posted October 26, 2012 Report Share Posted October 26, 2012 I'm not sure I can agree with you, Edward. I mean, correctness may be lacking in your country, but when it comes to code, it's pretty darn black and white, with little debate. Quote Link to post Share on other sites
markifornia 3 Posted October 26, 2012 Author Report Share Posted October 26, 2012 My apologies for dragging this on with a bland example (I'm still learning this whole deal about objects), but in this simple example dog has 3 properties - color, weight, and name. And then it has one method which is bark. var color = 'brown'; var weight = 50; var name = 'fido'; var dog = { color: color, weight: weight, name: name, bark: function() { var bark = 'woof!'; if(name == 'fido') { return 'bark'; } else { return 'meow'; } } }; alert(dog.color); alert(dog.weight); alert(dog.name); alert(dog.bark()); A comparison would be all the built in methods that javascript already comes with such as toLowerCase(); It's a method. var greeting = 'HELLO WORLD'; alert(greeting.toLowerCase()); Quote Link to post Share on other sites
markifornia 3 Posted October 26, 2012 Author Report Share Posted October 26, 2012 ehh the heck with it, I'll go with this. "A rose by any other name ...," I guess. Quote Link to post Share on other sites
Antonio Conte 426 Posted October 26, 2012 Report Share Posted October 26, 2012 Interesting thread. I agree with Jon. It would be possible to store the window object as a property inside the navigator object (for unknown reasons), but as the navigator object doesn't hold the window object, I'll agree with that the parent object must be the window object. That is also what I've always read. Quote Link to post Share on other sites
markifornia 3 Posted October 26, 2012 Author Report Share Posted October 26, 2012 I just took a look at Hartley's attached diagram. wow, I would have expected more native objects. Sure there are arrays, but this nice visual makes things much clearer. Thanks for that. Quote Link to post Share on other sites
Edward 108 Posted October 27, 2012 Report Share Posted October 27, 2012 Interesting thread. I agree with Jon. It would be possible to store the window object as a property inside the navigator object (for unknown reasons), but as the navigator object doesn't hold the window object, I'll agree with that the parent object must be the window object. That is also what I've always read. I actually found the website where i originally got this info from http://www.comptechdoc.org/independent/web/cgi/javamanual/javanavigator.html If the navigator is a representation of the client internet browser then technically it is higher level than the window object, even though the window object contains the navigator object. How can i window display a browser, the window is displayed in the browser, i guess this is what this guy was implying. Whatever though i don't really care, document and window are enough for me to get my work done and make $$$. Quote Link to post Share on other sites
Edward 108 Posted October 27, 2012 Report Share Posted October 27, 2012 Hmmm... I don't think that's right. I only hesitate to say that with 100% certainty because there are some sights out there that claim the navigator object is above the window object, but that makes no sense since window.navigator is used. I'm pretty sure the following is right: http://www.irt.org/a...s169/object.gif Actually, after testing things, I'm certain that the window object is the top object and the navigator is in the window object. Run the following JS code: for (var prop in window) { document.body.innerHTML += prop + '<br>'; } You'll see navigator in the list. Then run this code: for (var prop in navigator) { document.body.innerHTML += prop + '<br>'; } No window object. That settles that. Its a nice diagram you have there, i checked to see if i can could find a contact for that guy on http://www.comptechdoc.org/independent/web/cgi/javamanual/ but there is no contact email. May be we can find one through his whois, we need to write into him and ask him to update his misleading website. The trouble is if we were to keep pinching every small point we would never get anything done, somethings we need to let them be. Quote Link to post Share on other sites
HartleySan 826 Posted October 27, 2012 Report Share Posted October 27, 2012 It's very possible that that information was correct. JS started back during the days of Netscape Navigator, and the language and specs have changed a lot since then. The site looks old, so maybe that info used to be right; it makes sense for the top JS object in Netscape Navigator to be the navigator object. Edit: I found a Contact Us link on the page, but it's broken. It's obviously a very old site (relatively speaking), and hasn't been updated for a long time. Quote Link to post Share on other sites
Edward 108 Posted October 27, 2012 Report Share Posted October 27, 2012 I was thinking along those lines also. I checked the W3schools site and it was identical as to your earlier confirmation. Well its been interesting this thread never the less. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.