Closed myphysicslab closed 8 years ago
new HTMLOptionElement.Option();
gives a TypeError
in Chrome.
I think new Option()
should still be used: https://github.com/google/closure-compiler/blob/42a3cc26b3588450770a450027aad0c56a2698dd/externs/browser/deprecated.js#L33-L40
What error did you see when you had it the previous way?
Here is the error:
found : Option
required: (HTMLOptionElement|null)
this.selectMenu_.options[i] = new Option(this.choices_[i]);
^
1 error(s), 0 warning(s), 99.4% typed
Here is the definition of selectMenu_
/**
* @type {!HTMLSelectElement}
* @private
*/
this.selectMenu_ =
/** @type {!HTMLSelectElement} */(document.createElement('select'));
This was compiling with the previous compiler version from Nov 2015.
@myphysicslab Please see if https://github.com/google/closure-compiler/pull/1760 fixes it. Technically it should be an alias but I think @extends
will work in most cases. This is a non-standard deprecated API anyway.
Yes, #1760 fixes it. I made that change in my local version of the compiler, rebuilt the compiler, and now the original version of the line is compiling with no warning or error:
this.selectMenu_.options[i] = new Option(this.choices_[i]);
@myphysicslab Great, thanks. I don't expect #1760 to cause breakages internally at Google but we will see how it goes :)
After updating to the latest compiler (previously I was using version from Nov 2015) I had to change this line
to this:
I tried doing this:
and that compiled OK, but results in runtime errors:
Note also that
new HTMLOptionElement()
does not allow arguments in the constructor.Here are some of the relevant online docs:
http://www.w3.org/TR/2012/WD-html5-20121025/the-option-element.html#dom-option
https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement/Option
https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement
That last reference seems to imply that the
Option
constructor should be available like this:and that it should take four values.