header parallax image
uncoditional

code liberated

  • Home
  • Pete
  • Home
  • Pete
JQuery and CSS

3 JavaScript Lessons: Hoisting, console.log and deep object copy

January 23, 2013Peter Lombardo2830 views

Whew! several days of debugging later, i found not one but three magic bullets to my problem.

1. Beware of Javscript Hoisting!!!! Always, always, always var scope your function-specific variables at the top of your javascript function. Lest you find debugging a nightmare because hoisting will initially declare your variables as undefined via its hoisting “feature”. http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting

2. Lesson number 2: console.log only shows final state of an object, not “current” state. Use console.dir instead. http://stackoverflow.com/questions/7389069/console-log-object-at-current-state

3. Final lesson!!! jquery clone() has an option to do a deep copy rather than a shallow copy objects! http://stackoverflow.com/questions/122102/what-is-the-most-efficient-way-to-clone-a-javascript-object

so my problem wasn’t one thing, but three things all confusing the $#!@@#$ out of me. Hope this posts saves you some of the same pain.

consolefirebugjavascriptjquery
  • tweet
previous story

Focus on the person and the information will follow.

next story

CSS Background broken in ie9 on dev box (no ssl certificate).

Peter Lombardo

Peter Lombardo

Web developer too long.

you might also like

real Chrome developer features

October 8, 2014

CSS Background broken in ie9 on dev box (no ssl certificate).

February 15, 2013

Reloading a Div that was populated with JQuery’s $.load()

November 7, 2012

Leave a Response Cancel reply

You must be logged in to post a comment.

about me

uncoditional

Pete Lombardo

I like people and coding. Both change. Twenty years of full-stack development. I live in Maryland.

Recent Posts

  •   lives on!
    									
  • Cannot find module ‘…/…’ or its corresponding type declarations.
  • *ngIf – use parentheses
  • Angular component code block execution order
  • material dialog- how to get response data .subscribe()

Recent Comments

    Archives

    • June 2022
    • March 2022
    • June 2020
    • June 2019
    • November 2017
    • October 2017
    • September 2017
    • August 2017
    • June 2017
    • June 2015
    • May 2015
    • April 2015
    • October 2014
    • September 2014
    • July 2014
    • June 2014
    • May 2013
    • February 2013
    • January 2013
    • November 2012
    • October 2012

    Categories

    • angular
    • AWS
    • before the code
    • Browser Support
    • CFML & Mach-II
    • Chromebook
    • ckEditor
    • CloudSearch
    • ColdFusion
    • Java
    • javascript/typescript
    • JQuery and CSS
    • Languages
    • Life
    • material design
    • project
    • Projects
    • SNS
    • SQL
    • Tools
    • Uncategorized
    • unCODitional

    Meta

    • Log in
    • Entries feed
    • Comments feed
    • WordPress.org
    0
    Followers
    0
    Followers
    0
    Followers
    0
    Followers

    Follow @ Instagram

    Configuration error or no pictures...