This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 21744 - Speech utterance example missing "new" keyword, and constructor missing return value when called as function
Summary: Speech utterance example missing "new" keyword, and constructor missing retur...
Status: RESOLVED FIXED
Alias: None
Product: Speech API
Classification: Unclassified
Component: Speech API (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Glen Shires
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-18 19:54 UTC by James Craig
Modified: 2013-09-24 16:04 UTC (History)
2 users (show)

See Also:


Attachments

Description James Craig 2013-04-18 19:54:39 UTC
Originally filed 3 Apr 2013 as a mailing list comment:
http://lists.w3.org/Archives/Public/public-speech-api/2013Apr/0000.html

Speech utterance example missing "new" keyword.
https://dvcs.w3.org/hg/speech-api/raw-file/tip/speechapi.html#examples-synthesis

speechSynthesis.speak(SpeechSynthesisUtterance('Hello World'));

should be:

speechSynthesis.speak(new SpeechSynthesisUtterance('Hello World'));

As it is currently written, it will throw a ~"constructor is not a function" error in WebKit. 

The working group might wish to consider if you want the constructor to return a value when called without the new keyword. For example, Date() returns a string value for the current datetime, or a Date object if prefixed with the “new" keyword. 

> Date()
"Wed Apr 03 2013 16:40:46 GMT-0700 (PDT)"
> new Date()
Wed Apr 03 2013 16:40:46 GMT-0700 (PDT)

> typeof Date()
string
> typeof new Date()
object

I'd lean toward making SpeechSynthesisUtteranceConstructor, when called as a function, return a SpeechSynthesisUtterance instance (effectively making the new keyword optional) but I don’t believe the current spec allows this. I may be wrong.
Comment 1 Dominic Mazzoni 2013-04-24 22:06:01 UTC
Let's change the example to have "new" before SpeechSynthesisUtterance().

I have no strong opinion on whether we should allow "new" to be optional, but at first glance, it doesn't feel right to me - "new" is still required for things like XMLHttpRequest, and Date() is more of an exceptional case.
Comment 2 Glen Shires 2013-09-11 08:31:56 UTC
I propose the following errata.
If there's no disagreement, I'll add this to the errata page on Sept 24.

Section 6.2 Example 1:
"speechSynthesis.speak(SpeechSynthesisUtterance('Hello World'));" should be
"speechSynthesis.speak(new SpeechSynthesisUtterance('Hello World'));".
Comment 3 Glen Shires 2013-09-24 16:04:57 UTC
I've updated the errata (E09) with the above change:
https://dvcs.w3.org/hg/speech-api/rev/819c4810d8dc

As always, the current errata is at:
http://dvcs.w3.org/hg/speech-api/raw-file/tip/speechapi-errata.html