Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

First of all, indent and use whitespace consistently. I find using braces always a good style too.

Do not pollute the global namespace: wrap everything in a function that keeps the variables local to a smaller scope. Also use "use strict"; "use strict"; and test in Firefox as it is one of the least lenient browsers in strict mode:

(function ourAlarmCode () {
 "use strict";
 var sound = ...
 // all your code goes here
}());

Use consistent variable naming - usually CamelCase signifies a constructor, thus on instead of On, since it is not a constructor.

Name all the functions, even if you store them in variables - this makes debugging easier.

var numCap = function numCap (obj, min, max) {

Do not use random properties on DOM objects - instead store them as variables - thus replace aSwitch.On with var alarmOn = false;.

The switch can be replaced with an if

// toggle
alarmOn = !alarmOn;
if (alarmOn) {
 aSwitch.value = "ON";
 alarmSet();
}
else {
 aSwitch.value = "OFF";
 clearTimeout(alarmTimer);
}

Also, setTimeout is not guaranteed to trigger after exactly N milliseconds - in this case does not matter but in general it should be kept in mind that it is a time-out functionality to ensure that at least N milliseconds have elapsed since the callback is invoked.

First of all, indent and use whitespace consistently. I find using braces always a good style too.

Do not pollute the global namespace: wrap everything in a function that keeps the variables local to a smaller scope. Also use "use strict"; and test in Firefox as it is one of the least lenient browsers in strict mode:

(function ourAlarmCode () {
 "use strict";
 var sound = ...
 // all your code goes here
}());

Use consistent variable naming - usually CamelCase signifies a constructor, thus on instead of On, since it is not a constructor.

Name all the functions, even if you store them in variables - this makes debugging easier.

var numCap = function numCap (obj, min, max) {

Do not use random properties on DOM objects - instead store them as variables - thus replace aSwitch.On with var alarmOn = false;.

The switch can be replaced with an if

// toggle
alarmOn = !alarmOn;
if (alarmOn) {
 aSwitch.value = "ON";
 alarmSet();
}
else {
 aSwitch.value = "OFF";
 clearTimeout(alarmTimer);
}

Also, setTimeout is not guaranteed to trigger after exactly N milliseconds - in this case does not matter but in general it should be kept in mind that it is a time-out functionality to ensure that at least N milliseconds have elapsed since the callback is invoked.

First of all, indent and use whitespace consistently. I find using braces always a good style too.

Do not pollute the global namespace: wrap everything in a function that keeps the variables local to a smaller scope. Also use "use strict"; and test in Firefox as it is one of the least lenient browsers in strict mode:

(function ourAlarmCode () {
 "use strict";
 var sound = ...
 // all your code goes here
}());

Use consistent variable naming - usually CamelCase signifies a constructor, thus on instead of On, since it is not a constructor.

Name all the functions, even if you store them in variables - this makes debugging easier.

var numCap = function numCap (obj, min, max) {

Do not use random properties on DOM objects - instead store them as variables - thus replace aSwitch.On with var alarmOn = false;.

The switch can be replaced with an if

// toggle
alarmOn = !alarmOn;
if (alarmOn) {
 aSwitch.value = "ON";
 alarmSet();
}
else {
 aSwitch.value = "OFF";
 clearTimeout(alarmTimer);
}

Also, setTimeout is not guaranteed to trigger after exactly N milliseconds - in this case does not matter but in general it should be kept in mind that it is a time-out functionality to ensure that at least N milliseconds have elapsed since the callback is invoked.

added 501 characters in body
Source Link

First of all, indent and use whitespace consistently. I find using braces always a good style too.

Do not pollute the global namespace: wrap everything in a function that keeps the variables local to a smaller scope. Also use "use strict"; and test in Firefox as it is one of the least lenient browsers in strict mode:

(function ourAlarmCode () {
 "use strict";
 var sound = ...
 // all your code goes here
}());

Use consistent variable naming - usually CamelCase signifies a constructor, thus on instead of On, since it is not a constructor.

Name all the functions, even if you store them in variables - this makes debugging easier.

var numCap = function numCap (obj, min, max) {

Do not use random properties on DOM objects - instead store them as variables - thus replace aSwitch.On with var alarmOn = false;.

The switch can be replaced with an if

// toggle
alarmOn = !alarmOn;
if (alarmOn) {
 aSwitch.value = "ON";
 alarmSet();
}
else {
 aSwitch.value = "OFF";
 clearTimeout(alarmTimer);
}

Also, setTimeout is not guaranteed to trigger after exactly N milliseconds - in this case does not matter but in general it should be kept in mind that it is a time-out functionality to ensure that at least N milliseconds have elapsed since the callback is invoked.

First of all, indent and use whitespace consistently.

Do not pollute the global namespace: wrap everything in a function that keeps the variables local to a smaller scope:

(function () {
 var sound = ...
}());

Use consistent variable naming - usually CamelCase signifies a constructor, thus on instead of On, since it is not a constructor.

Do not use random properties on DOM objects - instead store them as variables - thus replace aSwitch.On with var alarmOn = false;.

The switch can be replaced with an if

// toggle
alarmOn = !alarmOn;
if (alarmOn) {
 aSwitch.value = "ON";
 alarmSet();
}
else {
 aSwitch.value = "OFF";
 clearTimeout(alarmTimer);
}

Also, setTimeout is not guaranteed to trigger after exactly N milliseconds - in this case does not matter but in general it should be kept in mind that it is a time-out functionality to ensure that at least N milliseconds have elapsed since the callback is invoked.

First of all, indent and use whitespace consistently. I find using braces always a good style too.

Do not pollute the global namespace: wrap everything in a function that keeps the variables local to a smaller scope. Also use "use strict"; and test in Firefox as it is one of the least lenient browsers in strict mode:

(function ourAlarmCode () {
 "use strict";
 var sound = ...
 // all your code goes here
}());

Use consistent variable naming - usually CamelCase signifies a constructor, thus on instead of On, since it is not a constructor.

Name all the functions, even if you store them in variables - this makes debugging easier.

var numCap = function numCap (obj, min, max) {

Do not use random properties on DOM objects - instead store them as variables - thus replace aSwitch.On with var alarmOn = false;.

The switch can be replaced with an if

// toggle
alarmOn = !alarmOn;
if (alarmOn) {
 aSwitch.value = "ON";
 alarmSet();
}
else {
 aSwitch.value = "OFF";
 clearTimeout(alarmTimer);
}

Also, setTimeout is not guaranteed to trigger after exactly N milliseconds - in this case does not matter but in general it should be kept in mind that it is a time-out functionality to ensure that at least N milliseconds have elapsed since the callback is invoked.

Source Link

First of all, indent and use whitespace consistently.

Do not pollute the global namespace: wrap everything in a function that keeps the variables local to a smaller scope:

(function () {
 var sound = ...
}());

Use consistent variable naming - usually CamelCase signifies a constructor, thus on instead of On, since it is not a constructor.

Do not use random properties on DOM objects - instead store them as variables - thus replace aSwitch.On with var alarmOn = false;.

The switch can be replaced with an if

// toggle
alarmOn = !alarmOn;
if (alarmOn) {
 aSwitch.value = "ON";
 alarmSet();
}
else {
 aSwitch.value = "OFF";
 clearTimeout(alarmTimer);
}

Also, setTimeout is not guaranteed to trigger after exactly N milliseconds - in this case does not matter but in general it should be kept in mind that it is a time-out functionality to ensure that at least N milliseconds have elapsed since the callback is invoked.

default

AltStyle によって変換されたページ (->オリジナル) /