0

I would like to know if this is possible:
I want to access a index of an object that point for another index in the same object..
example:

var object = {
 edit: function (string) {
 alert(string);
 },
 edit2: "call default edit()"
};
object.edit2("Hello World!!");

How can I do that?
Sorry my english is.. bad

Jaak Kütt
2,6864 gold badges35 silver badges41 bronze badges
asked Jan 3, 2014 at 22:20
1
  • What is "index of an object that point for another index in the same object"? Commented Dec 26, 2024 at 22:29

3 Answers 3

3

You could just do it like this

var object = {
 edit : function(string){
 alert(string);
 },
 edit2 :function(string){
 this.edit(string);
 }
};
object.edit2("Hello World!!");
Blundering Philosopher
6,8492 gold badges46 silver badges63 bronze badges
answered Jan 3, 2014 at 22:23
Sign up to request clarification or add additional context in comments.

2 Comments

Ahh, you beat me to it.
Like ninjas - Thanksss XD
1

How about this:

var object = {edit : function(string){alert(string)},
 edit2 : function(string){this.edit(string)}
}
object.edit2("Hello World!!")
answered Jan 3, 2014 at 22:24

Comments

0

I think Javascript allow:

var object = {edit : function(string){alert(string)} };
object.edit2 = object.edit;
object.edit2("Hello World!!")

or scrblnrd3's solution.

This website is international, so i guess you're not the only one who don't speak very well english... (Why are you looking at me ?)

answered Jan 3, 2014 at 22:29

Comments

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.