small medium large xlarge

Generic-user-small
24 Sep 2014, 05:21
Indranil Chakraborty (1 post)

Hi, This code is not working as when I run this in Chrome it gives me the following error,

var Parent = can.Construct.extend({ init: function(count) { this.count = count; }, increase: function() { this.count++; }, read: function(prefix) { return prefix + “ “ + String(this.count); } });

  var Child = Parent({
    // Child inherits the init function

    // Override increase
    increase: function() {
      this.count += 10;
    },
    // Add new function: decrease
    decrease: function() {
      this.count--;
    },
    // Override read, but call parent's version
    read: function() {
      return this._super("Count is") + "!";
    }
  });
  
  var child = new Child(2); // calls Parent's init
  child.increase(); // calls Child's increase
  child.decrease(); // calls Child's decrease
  child.count; // returns 11
  child.read(); // returns "Count is 11!"     

This error comes in Uncaught TypeError: undefined is not a function

The following line has the error, and I am unable to resolve this error as I could not find much on the web for CanJS on this.

return this._super(“Count is”) + “!”;

I am using jquery version jquery-1.11.1.js, and yours 1.10.2, could this be a problem or I have to use a different version of CanJS

Please do let me know, the solution ASAP, I am new to CanJS and jquery.

-Indronil Chakroborty

Freddy_avatar_pragsmall
19 Oct 2014, 01:48
Fred Daoud (22 posts)

Did you include all canjs extensions?

Photo on 2013-11-16 at 17.13 #4_pragsmall
03 Dec 2014, 20:56
Apoorv Nag (1 post)

You have to include can.construct.super.js as shown

You must be logged in to comment