Let’s say I have the following code snippet.
function test(id) { alert(id); }
testChild.prototype = new test();
function testChild(){}
var instance = new testChild('hi');
Is it possible to get alert('hi')? I get undefined now.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That’s how you do this in CoffeeScript:
Nope, I’m not starting a holy war. Instead, I’m suggesting to take a look at resulting JavaScript code to see how subclassing could be implemented:
See it in action at http://jsfiddle.net/NGLMW/3/.
To stay correct, the code is slightly modified and commented to be more readable, compared to CoffeeScript output.