inheritance in javascript
hello,
this goes out to all js programmers out there, so it seems from the looks of things that js is so dynamic right (at least at the moment) that its authors at EMCA have left the inheritance issue open. (to both the advantage and confusion or even dismay of developers) okay , enough of the small talk does anybody know how inheritance goes in js? here is some code that you may take as a benchmark (THIS CODE IS IMPROVISED) Code:
function point(){ // class point |
What is exactly the problem ?
|
Quote:
i thought the question was obvious.. cheers |
Quote:
And are functions first class objects in JavaScript ? |
Anyway, can't you simply call 'point' constructor inside 'circle' constructor ? And then implement 'circle' methods by simply calling 'point' instance methods ?
|
Quote:
for starters the function set_position and get_position used in point are eventually gonna be the same ones used for circle since every circle has a point (it's called the CENTER of circle) Quote:
all i can say is that , what you've seen is the common syntax used to declare js classes and their methods and variables. btw , it looks from the signature of yours that you're more knowledgable in python than in js , you don't have to solve this problem if this is outside of realm of expertize... cheers |
Quote:
Code:
// inheritance exercise i need a technique in js that automatically does this operation without having to "inherit" every single function manually in other words i need syntactic sugar ! cheers |
Quote:
Regarding the need of syntactic sugar - write or use a text preprocessor. |
Quote:
Javascript is an INTERPRETED language there is no pre-processing ! the issue is HOW to do inheritance in js not to explain why , that's beyond the scope this thread.. |
Quote:
In fact, I have my own preprocessor written in Perl and sometimes I use it to produce Perl code. |
Quote:
|
Quote:
you're suggesting to use a server side language such as php , perl ..etc to write the necessary javascript in realtime before being submitted to the browser.... well what you've described is what we web developers refer to as a "browser hack" (remember this term) and it's NOT an option ! because : 1) it shifts the load back on the server which is what client side scripting languages such as js are supposed to solve. 2) it complicates things and makes debugging js code a mess Quote:
cheers |
Quote:
And Quote:
|
http://www.brighthub.com/computing/l...les/19626.aspx :
Quote:
|
Quote:
|
All times are GMT -5. The time now is 12:20 AM. |