-
Notifications
You must be signed in to change notification settings - Fork 346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a forum for this book? #2
Comments
Hi Zach, name = name + "img/.jpg"; if name is "zero", then you're going to get "zeroimg/.jpg" because the So to get "img/zero.jpg" you'd need to write: name = "img/" + name + ".jpg"; Hope that makes sense. Elisabeth On Sun, Mar 1, 2015 at 5:32 PM, Zach Sosana [email protected]
|
Oh no accidently deleted last commit. I didn't see this prior but figured it out! Thanks for responding and the explanation. It makes total sense but what was funny is I tried first putting "img/" after name when I reversed them I was grinning from ear to ear :) like the example you shown above. |
Hi Beth, I was working with the sort method, in the sharpen your pencil excercise it mentions a possible solution that could minimize that amount of code lines. I commented the solution out below. function compareSold(colaA, colaB) { But I could not get this to work for sorting alphabetically. What is a common solution would you recommend to sorting alphabetically? or would the code above be an okay practice? Obviously the less lines of code the better right? Another question I had was that the book mentions that the sort method is destrucitive. It changes the array, rather than return a new array. Would the disadvantage be that we are mutating the array rather than returning a new altered array? Is it considered a disadvantage? And if we wanted to return a new one is there another method we would use? like toSource()? |
Hi Zach, colaA.sold - colaB.sold because you want to return a number. colaA and colaB are objects, so To sort alphabetically you have to use colaA.name and colaB.name. There's no disadvantage to sort being destructive as long as you know your var arrayCopy = myArray; because arrays are objects, so they are reference variables! If you do the So you actually need to write a loop and copy each value from myArray into The only reason you'd need to do this is if you need both the original Beth On Mon, Mar 16, 2015 at 7:32 PM, Zach Sosana [email protected]
|
Thank you so much for taking the time to respond and answer. This makes sense now. |
back again :) I am trying to make sure I have a firm grasp on how nested functions affects scopes. In the flyAndQuack example we have two functions with nested funcitons. The fly function is a function expression which will will be evaluated during the second pass when the broswer is executing the code at run time. While the function quack is a declaration function which is parsed first before being evaluated at run time. Inside the quack function there is a function expression which if I understand this will not be evaluated within the scope when the browser goes through the first pass. In the second pass, is when the browser will excute the function expression nested within the quack. Hoping this is the right place to ask questions :) |
Hi Zach, Regarding the nested functions (that is, wingFlapper and quacker):
Think of function expressions as just like regular variables, and function declarations as a bit special because they are defined everywhere in their scope. Hope that helps. |
Hi Beth, is it possible we could create a tag for questions? That way future students could post under this tag for future questions or search through them. If I understand this, I thought that since fly was a expression everythiing nested inside would be ignored during the first pass but if I read your comments correctly the browser parser may do this during the first pass but not executed till the second pass do to fly being a expression function. What I was trying to make sure is my understanding of what will be excuted during the first pass and what will be executed during the second pass for nested functions. I found it interesting that the quack function will have two passes, the first pass which sees its a declaration, but than notices the expression and ignores it causing it to have two passes. This has to have a disadvanage of some sort in the future? the fact it takes two passes for execution. I found some interesting conclusions during my QA. One was changing the for loop above as you mentioned but what really clicked was when I changed quacker from an expression to a declaration inside of the function quack. I noticed that it was executed before the fly function was called. This lead me to believe even though the quack is a delaration, that if you have a nested expression it will be ignored but if it was a declartion inside of it, it would be executed during the first pass and also would not have to have two passes. I could of sworn there was a reason for not doing declaration over expression mentioned earlier in the book, but need to double check my notes from earlier chapters. I also really enjoyed your concrete example tracing through invoking functions. Light bulb went off and was like now this makes total sense! |
Keep in mind there is a distinction between parsing the function - that is, Either a declaration or expression is fine as long as you understand where On Thu, Mar 19, 2015 at 11:49 AM, Zach Sosana [email protected]
|
Hi Beth, Don't have access to update this thread to be labeled under question. Can you tag this under the questions label? |
Curious if there is a forum for this book and if that is the proper avenue to ask questions.
Thanks
The text was updated successfully, but these errors were encountered: