Hacker News new | past | comments | ask | show | jobs | submit login

if you dont use prototype the function will not belong το the new object you create, therefore you will not be able το call the function from settimeout, which was the problem the author assumed το have.



Try extending the time on your timeout in the example, say to 30000 milliseconds. You might get a surprise when you see your function get called immediatley.

In the article, you are right that he should use prototype, but not for the reason you mention. In the example, he does this.foo = function, so the function does get associated with the object. The problem is that the function gets recreated every time the HotDog constrictor gets called. Better to put getCondiments on the prototype, so that it is only defined once.


Sorry, I was typing a bit fast. This should be ok.

  window.onload= function() {  
	setTimeout( "myHotDog.getCondiments();", 3000);
  };




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: