2

I think the Function object is the only instance in the JavaScript. All the other function(){...} or var xx=function(){...} are the objects inherited from this Function object. That is the prototype based language feature. And in prototype based language there is no Class, and One of the advantages of it is the object can changed anytimes.such as add a method or add a property into it. So, I think we can treat object like a key-values collection. You can add items into it anytimes after you created it. (If I was wrong, Please correct me.)

Say you have the code:

 Function.test=function(){
 alert(Function.name);//"Function" 
 alert(Function.myName);//"fun"
 };
 Function.name="fun";
 Function.myName="fun";
 Function.test();

In the above code, all I want to do is add a test method to the Function object. There is no error found in this code. But why Function.name can not be changed?

Peter O.
33.1k14 gold badges86 silver badges97 bronze badges
asked Apr 22, 2013 at 6:17
2
  • Wat way have u defined Function()? Commented Apr 22, 2013 at 6:22
  • I don't know how to answer your question... Function is the build-in object of javascript. Commented Apr 22, 2013 at 6:39

2 Answers 2

0

First of all this property is not standard. This means that different browsers may treat it as they want. The second thing is that according to MDN it is read only.

answered Apr 22, 2013 at 6:30
Sign up to request clarification or add additional context in comments.

Comments

0

A page from MDN states that the name of the Function cannot be changed because it's read only.

techfoobar
66.8k14 gold badges117 silver badges138 bronze badges
answered Apr 22, 2013 at 6:20

1 Comment

Hi, @Joseph the Dreamer, IE8 can change it . It is not readonly.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.