Question
I noticed that in tizen.js, there's a function called "new array()" written with a lowercase 'a' instead of the standard "new Array()". For example:
AlarmAbsolute.prototype.daysOfTheWeek = new array();
This results in an error:
ReferenceError: Can not find variable: array
Why would the code use "new array()" instead of the correct "new Array()" syntax?
Answer
Problem Understanding
The issue arises from using incorrect JavaScript syntax. In JavaScript, array constructors must be called with Array (capital A) rather than array (lowercase a). The JavaScript engine is case-sensitive and cannot recognize array as a valid constructor.
Solution Methods
- Replace all instances of
new array()withnew Array() - Alternatively, use array literal notation
[]which is the preferred modern syntax
Code Examples
Here's the corrected version using proper Array constructor:
function AlarmAbsolute() {};
AlarmAbsolute.prototype.daysOfTheWeek = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
console.log(AlarmAbsolute.prototype.daysOfTheWeek);
Or using array literal syntax (recommended):
function AlarmAbsolute() {};
AlarmAbsolute.prototype.daysOfTheWeek = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
console.log(AlarmAbsolute.prototype.daysOfTheWeek);
Additional Tips
- Always use proper JavaScript casing for built-in objects (Array, Object, String, etc.)
- Consider using array literals
[]instead of the Array constructor for better performance and readability - If you encounter this error in tizen.js, it might be worth checking if you're using the correct version of the file