resetting Function.prototype

P

Peter Michaux

Hi,

I'd like to have "class methods" inherit. Is there a way that isn't
copying properties from one function to another? I tried to do the
following with no luck.

function Person() {}
Person.classMethod = function() {
return 'classMethod';
};

Function.prototype = Person;
var Employee = new Function('alert("Employee");');

alert(Person.classMethod());
alert(Employee.classMethod());

I don't get an error when I assign to Function.prototype but I do see
the error "Employee.classMethod is not a function"

Any ideas?

Thanks,
Peter
 
R

RobG

Hi,

I'd like to have "class methods" inherit. Is there a way that isn't
copying properties from one function to another? I tried to do the
following with no luck.

function Person() {}
Person.classMethod = function() {
return 'classMethod';
};

Function.prototype = Person;
var Employee = new Function('alert("Employee");');

alert(Person.classMethod());
alert(Employee.classMethod());

I don't get an error when I assign to Function.prototype but I do see
the error "Employee.classMethod is not a function"

Any ideas?

15.3.3.1 Function.prototype
The initial value of Function.prototype is the Function prototype
object (section 15.3.4).
This property has the attributes { DontEnum, DontDelete, ReadOnly }.

Specs are handy sometimes. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,609
Members
45,253
Latest member
BlytheFant

Latest Threads

Top