![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Is the following code valid and supported by current implementations? function somename() { this.show = function () { document.write("somename called") } } var somename = new somename(); somename.show() Note that the class name "somename" is reused for the variable name. |
#3
| |||
| |||
|
|
Is the following code valid and supported by current implementations? function somename() { this.show = function () { document.write("somename called") } } var somename = new somename(); somename.show() Note that the class name "somename" is reused for the variable name. |
#4
| |||
| |||
|
|
No, its invalid, because JavaScript does not have classes, only objects. A 'function myclass()' would create a function (which is an object) myclass capable of building and returning objects. You can see this by attempting to do the following after your code. someother = new somename(); someother.show(); would result in an error, because it would attempt to build an object from something that is now another object. |
#5
| |||
| |||
|
|
Klaus Johannes Rusch wrote: Is the following code valid and supported by current implementations? No, its invalid, [...] |
#6
| ||||
| ||||
|
|
Is the following code valid and supported by current implementations? |
|
function somename() { this.show = function () { document.write("somename called") } } |
|
var somename = new somename(); |
|
somename.show() Note that the class name "somename" is reused for the variable name. |
#7
| |||
| |||
|
#8
| |||
| |||
|
|
Well, maybe not invalid, but I can't really think of any circumstances this would really be useful. It won't make things more clear, thats for sure. The only reason might be obfuscation and making things unreachable. |
![]() |
| Thread Tools | |
| Display Modes | |
| |