views:

45

answers:

2

I'm somewhat new to object oriented programming in Javascript and I'm trying to build a handler object and library for a list of items I get back from an API call. Ideally, I'd like the library functions to be members of the handler class. I'm having trouble getting my class method to work however. I defined as part of the class bcObject the method getModifiedDateTime, but when I try to echo the result of the objects call to this method, I get this error:

Error on line 44 position 26: Expected ';'
    this.getModifiedDateTime: function(epochtime) {

which leads me to believe that I simply have a syntax issue with my method definition but I can't figure out where.

response(
    {
        "items":
        [
            {"id":711,"name":"Shuttle","lastModifiedDate":"1268426336727"},
            {"id":754,"name":"Formula1","lastModifiedDate":"1270121717721"}
        ],
        "extraListItemsAttr1":"blah",
        "extraListItemsAttr2":"blah2"
    });

function response(MyObject) {
    bcObject = new bcObject(MyObject);

    thing = bcObject.getModifiedDateTime(bcObject.videoItem[0].lastModifiedDate);
    SOSE.Echo(thing);
}   

function bcObject(listObject) {
  // define class members
  this.responseList = {};
  this.videoCount = 0;
    this.videoItem = [];
    this.responseListError = "";

    // instantiate members
    this.responseList = listObject;
    this.videoCount = listObject.items.length;

    // populate videoItem array
    for (i=0;i<this.videoCount;i++) {
        this.videoItem[i] = listObject.items[i];
    }

    this.getModifiedDateTime: function(epochtime) {
        var dateStringOutput = "";
        var myDate = new Date(epochtime);
        dateStringOutput = myDate.toLocaleString();
        return dateStringOutput;
    };
}
+3  A: 

You use = to assign values in JS, not ::

this.getModifiedDateTime = function(epochtime) {
Matti Virkkunen
+2  A: 

You should use the = operator for methods defined as you did there (this.<methodName> = function (...) {).

The colon notation is used when declaring object literals.

Alex Ciminian