JavaScript: using constructor without operator 'new'
Posted
by GetFree
on Stack Overflow
See other posts from Stack Overflow
or by GetFree
Published on 2009-12-18T13:56:54Z
Indexed on
2010/03/23
19:33 UTC
Read the original article
Hit count: 334
Please help me to understand why the following code works:
<script>
var re = RegExp('\\ba\\b') ;
alert(re.test('a')) ;
alert(re.test('ab')) ;
</script>
In the first line there is no new
operator.
As far as I know, a contructor in JavaScript is a function that initialize objects created by the operator new
and they are not meant to return anything.
© Stack Overflow or respective owner