0

What is this?

en4.activity.like(c)

Is this a function like() of property 'activity' of object en4?

I need to re-write the function but in the same format and I'm confused.

1
  • what is en4? Is this an instance or an object (direct instance of an object)? Commented Dec 30, 2012 at 22:01

2 Answers 2

3

This would do the job:

var en4 = {
    activity: {
        like: function(c) {

        }
    }
};

In case en4 already exists and also has a property activity you'd do it like this:

en4.activity.like = function(c) {
    ...
};

If that property also doesn't exist:

en4.activity = {
    like: function(c) {

    }
};

Since you just have a single object there is most likely no need to involve prototypes at all.

Sign up to request clarification or add additional context in comments.

2 Comments

If en4 exists but has no property activity, does the last example still work?
Nope, in this case it would have to be created first, too.
1

Try this:

function nsp() {
    this.activity = {
        like: function(a) {}
    };
}

var en4 = new nsp();

en4.activity.like(c);

Comments

Your Answer

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.