Jump to content
Larry Ullman's Book Forums

QuakeLive

Members
  • Posts

    50
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by QuakeLive

  1. Quote [page 413 - Character Classes... ]: But, ^\S$ does not check if a string contains no spaces, it only checks if a string is a non-white space character, right?
  2. Hi, I tested the example " Using the Cookie Library"... also I saw this in errata : and everything works fine, but I think that now the cookie is not renewed since the setTheme(theme) function does not create (set) any cookie. And, in the book there is the following text: But, in eratta it is not explained how to renew the cookie. What would be the best and most elegant way to do this? This is how I did: window.onload = function() { 'use strict'; document.getElementById('aTheme').onclick = setThemeCookie; document.getElementById('bTheme').onclick = setThemeCookie; var value = COOKIE.getCookie('theme'); if (value) { setTheme(value); var expire = new Date(); expire.setDate(expire.getDate() + 7); COOKIE.setCookie('theme', value, expire); } }; The original code was: window.onload = function() { 'use strict'; document.getElementById('aTheme').onclick = setThemeCookie; document.getElementById('bTheme').onclick = setThemeCookie; var theme = COOKIE.getCookie('theme'); if (theme) { setTheme(theme); } }; 2. I have another question: the cookie was created (for example, I clicked on the link 'aTheme'); then I browsed to some other website (for example, I opened google.com); and, finnaly, I oppened the same example (page) again (by entering path in a browser). Why theme is not remembered, CSS is not loaded? I need to click, to choose theme again to load CSS on the page? This applies to both - the code downloaded from this website, and for my code.
  3. At the beginning, I thought that I didn't understand some things about cookies well and that's why I asked: After that, I just gave my opinion, "splitting semantic-hairs" (or some kind of provocation by trying to find someone else's mistake) was not my intention. Anyway, now it is clear, thank you very much HartleySan and Larry!
  4. Thanks. I think that using "Cookies" instead of "Cookie values" is more correct (in the quotes above), because "cookie value" is just a part of the cookie (name-value, duration... )... but not sure, and it does not seem so important... Anyway, thank you again!
  5. Hi, Here are two quotes from Creating Cookie Library example: Would not it be better if instead of "cookie values" we use just "cookies" (... some browsers add a space in between the cookies in document.cookie. ) and "Decode the cookie" instead of "Decode the value"? Is it correct to say that "some browsers add a space in between the cookies in document.cookie" INSTEAD OF "some browsers add a space in between the cookie values in document.cookie" ??? Thank you in advance!
  6. Hi, I have a question about Creating Modal Windows example... Quote: If I remove the following lines (altogether, all three lines): In function openModal(): document.getElementById('openModal').onclick = null; In function closeModal(): document.getElementById('openModal').onclick = openModal; In function closeModal(): document.getElementById('closeModal').onclick = null; so that the new code looks like this: everything works well, there are no errors. I don't understand why there are these three lines? Thank you in advance!
  7. OK! Again, thank you so much HartleySan! I wish you a Happy New Year! All the best!
  8. Sorry for the late reply - thank you very much HartleySan! And what about attributes? For now, in the book I did not find anything, only that are treated as nodes... (also, I found something here). But, if all HTML attributes are attribute nodes - why in the previous example (with the number of children of paragraph) we didn't count attributes nodes? Or, there is an exception in the case of attributes nodes?
  9. Yes, thank you very much HartleySan. So, the object above the root node is document object. Let's look at this paragraph: <p>This is some text and if you click <a href="#">here</a>, something will happen.<br> This is another text.</p> 1. This paragraph has has three children (text node, A node and BR node), right? 2. The whole text is treated as one child, although there is some text before <a></a> element, some text is between <a></a> and <br> elements, and some text is after <br> element? 3. The only difference between childNodes property and children property is that children property excludes the TEXT nodes? And that's all?
  10. Hi, I started reading the chapter about Document Object Model, and I have a few beginner questions: 1. Quote from book: Isn't HTML element the root node? 2. Quote from book: But on http://www.w3schools.com/jsref/prop_node_nodetype.asp and https://developer.mozilla.org/en-US/docs/Web/API/Node.nodeType this is different: Also, what is the difference between "1 for an HTML element" and "10 for the HTML element"? I guess that's a mistake. Thank you in advance!
  11. Hi, I do not understand how does "it" know that argument e represents event that occured, not something else. What if that is some other argument, not representing event? Sorry for my bad English. Thank you in advance!
  12. Yes, my mistake, I need to check (test) before I ask... Thank you very much!
  13. Thank you HartleySan. If I understood correctly - that is just good practice (because of debugging)... But let's say that there is no that line: return true;. If the first statement in the function is satisfied - JS function will not return undefined (which loosely evaluates to false), right? If so, then why return true?
  14. Hi, I have one simple question about creating a utility library: Is it necessary to return true, and why this method must return true ? Thank you in advance
  15. I found this... where someone wrote that "The ES5 standard dictates that undefined is now readonly."
  16. Thank you HartleySan. This is what I didn't know... The problem is that when I test this - undefined is not equal to the number 42? (or I make a mistake somewhere? ) :
  17. HartleySan, THANK YOU SO MUCH! I still haven't started reading part of the book that relates to event handling, the last chapter that I read is Returning Values From Functions... But your post explains the difference between object.property = functionReference; and object.property = functionCall(); If I understood well, this is the point: - assigning a function call to the event handler actually causes the function assigned to the handler to be called immediately, and then assign the value returned by the function call to the event handler. - all a function reference is is something that says, "Call function xyz when the event occurs." Actually, as it is written in the book - with function reference a function definition can be a value assigned to a variable (object property)... All this is well explained in the book. The reason I got confused and I did not pay enough attention is because of the following example: (this is from book) When I tried to test - function definition was not returned when called function reference (don't know why?): (only "function()" is returned) Anyway, the point is that with function reference a function definition will be returned (and assigned... ), and with function call - the value returned by the function will be assigned... THANK YOU AGAIN, HartleySan!
  18. Ok, as I read the book, some things have changed, but there is still a problem. As for the example in my previous post, if there is ONLY function init() { //some code return something; } that does not mean that window.onload = init; would be wrong and cause some error, because for every function we can use identifier which is different from a function call. But, now, I do not understand what is the difference between identifier and a function call. I know that when you say: window.onload = init(); you actually called the init() function, and that's ok, BUT I do not understand what happens when you use function identifier: window.onload = init; if with this line I did not call a function which will do something, then what I actually did???
  19. Hi, I have one question about this. In the book it is written that "Doing the above would call the init() function and assign the value returned by it to the window.onload property, which is not the intent." Let's say that somewhere in JavaScript exsist the following code: var init = function() { //some code return something; } Here, a function definition is a value assigned to a variable. Now, we have: window.onload = init; and that code assigns to the onload property of the window object the value of the init variable. OK. Let's suppose that there exists the following function which does the same function init() { //some code return something; } In this case, it would be the same to use: window.onload = init; AND window.onload = init(); But in reality, this is not the case, there is no init() function, there is only init variable so it isn't the same. Am I right?
  20. Thank you HartleySan! Although I read this book, I do not think I understood some things well. For example: So, now undefined is number? And, if I understood well - it is better to use everywhere (typeof something != 'undefined'), for example: if (typeof output.textContent != 'undefined') { output.textContent = message; } else { output.innerText = message; } (than if (output.textContent !== undefined) { output.textContent = message; } else { output.innerText = message; } as used in the book?)
  21. Hi, I have one question about undefined: Do these two lines do the same thing? 1. if (typeof something != 'undefined') 2. if (something !== undefined) Thank you in advance!
×
×
  • Create New...