????[javascript] view plaincopy1. if (diff > measure) {

????2. num = Math.floor(diff / measure);

????3. diff = diff - (num * measure); // BUG: This was missing in our first attempt

????4. pieces.push(format(num?? consider[i]));

????5. }

????

????????????λ?????????ù??????????????е?console.log????????????????ж???console???????????б?????

?????????????

????Firebug???????????????javascript?????????????????????????console.log???????alert????????????????console??????UI??????????????????????????????console.log?????alert?????????????????????

?????????????????????????Firebug???????????????????????

??????÷????????????????????Щ????????????Ч???????????????????????????????Щ???

 ????Console.log??????

????Console.log?????????Щ?????????console.log??????????????????????????????????????????????????????????????????????????????????????????console?????????????????????Firebug?????????????“????JavaScript??????”?????????????“??????????????????????console??????????????”???????????????????????????????????????????????????

?????????????console.log?????????????????????????????????????????????????????????????????????????е?????????(??)???????????????????????????????????????2???????????????????????????????????????(Adhoc debugging)?????????????????????????

????????Ч????????

???????????????????????????????????????????????????????????console.log/alert???????????????????????????????????????????????

??????????????

??????????????????????????????????в???????磬???????????? jQuery.fn.differenceInWords?з???????????????????????????????????????????

????[javascript] view plaincopy1. var second = 1000;

????2. var minute = 60 * second;

????3. var hour = 60 * minute;

????4. var day = 24 * hour;

????5.

????6. try {

????7. // Test that 8 day difference results in "1 week ago"

????8. var dateStr = new Date(new Date() - 8 * day).toString();

????9. var element = jQuery('Replace me');

????10. element.differenceInWords();

????11.

????12. if (element.text() != "1 week ago") {

????13. throw new Error("8 day difference expected '1 week ago' got '"+

????14. element.text() + "'");

????15. }

????16.

????17. // Test a shorter date

????18. var diff = 3 * day + 2 * hour + 16 * minute + 10 * second;

????19. dateStr = new Date(new Date() - diff).toString();

????20. var element = jQuery('Replace me');

????21. element.differenceInWords();

????22.

????23. if (element.text() != "3 days?? 2 hours?? 16 minutes and 10 seconds ago") {

????24. throw new Error("Small date difference expected " +

????25. "'3 days?? 2 hours?? 16 minutes and 10 seconds ago' " +

????26. "got '" + element.text() + "'");

????27. }

????28.

????29. alert("All tests OK!");

????30. } catch (e) {

????31. alert("Assertion failed: " + e.message);

????32. }

??????????????????????????????????????????????????????????????????????????????????????????????????浽????????????????ò????????а????????????????????л???????????“???в???????”???????????????????

???????????????????????????????????????д?????????????????????????????????ò??ó???????????????????????????????????????????????????????????

?????ò?????????κ?????κ??????????????С?

??????????????????????????????????иò????????????????????????????????????

????????????????Щ?????????????????

???????????????????????????????????????????????????????????????д???

?????????????????г?????????????????????????????????????alert??console.log?????????

????д?ò??????????????Ч???????????д??Σ????????????′???????????????????????

???????????????

???????????д???????????????·??????????????к?????????????????????ò????????????????ò?????????е?????????????????????????????????????????????????????????????????????????