Question

Basically Dub and Dub.socialize objects already exist as an included library. I'm trying to extend the library with some additional custom functions that I created.

I attempted the following concept below:

Dub.socialize = {
    setUID : function(preUID, postUID)
    {
        // .. function code here
    }
}

However, I receive the following error "Uncaught TypeError: Cannot set property 'setUID' of undefined" from my console.

Obviously my knowledge of objects is a bit misled. What would be the proper method of extending this function into the already existing object library?

Was it helpful?

Solution

A simple solution could be

Dub.socialize.setUID =  function(preUID, postUID) {};

OTHER TIPS

Try this:

Dub.socialize.prototype.setUID = function(preUID, postUID) {
    ...
};

Object Constructor and prototyping

Edit: Realized you're working with a "static" object. This only works for something that is instantiated, and since you're not making new instances, this doesn't apply.

If you are going to create the function for declared object means then you have to use "prototype" keyword for example.

`var Dub = { socialize: new Object() };

Dub.socialize.prototype.setUID = function(preUID, postUID) { // Function Body };`

http://www.javascriptkit.com/javatutors/proto3.shtml

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top