Link to home
Start Free TrialLog in
Avatar of ethar turky
ethar turkyFlag for Saudi Arabia

asked on

jquery 3 and protoype

Dear all,
Once I upgrade to jquery 3.1.1, I got an error when I use prototype:
	Array.prototype.remove = function(from, to) {
	  var rest = this.slice((to || from) + 1 || this.length);
	  this.length = from < 0 ? this.length + from : from;
	  return this.push.apply(this, rest);
	};

Open in new window


PropertiesWindow.js:63 Uncaught TypeError: controller.remove is not a function
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

That error does not look like it pertains to the snippet you have posted.
Avatar of ethar turky

ASKER

Yes its for :
controller = new CategoryController(orignalData);
controller.init(options);
function CategoryController(dataArray) {
    if (dataArray) this.dataArray = dataArray;
    this.category = {};
    this.listObjectMap = {}; // each category with it's List.js object
}

CategoryController.prototype = {
    curGroupBy: "groupId",
    curSortBy: "asc",
    dataArray: [],
    categories: {},
    init: function (options) {
        this.groupBy(this.curGroupBy);
        this.render(options);
        
		var self = this; 
    }
};

Open in new window

Error raised :
PropertiesWindow.js:63 Uncaught TypeError: controller.init is not a function
This works for me
<script src="http://code.jquery.com/jquery-3.1.1.js"></script>
<script>
Array.prototype.remove = function(from, to) {
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);
};
var x = new Array();
x.push(1);
x.push(2);
x.push(3);
x.push(4);
x.push(5);
x.push(6);
x.push(7);
x.push(8);
console.log(x);
x.remove(3,6);
console.log(x);
</script>

Open in new window

what about the code I sent?
I am guessing it is an ordering issue - what happens if you try this
function CategoryController(dataArray) {
    if (dataArray) this.dataArray = dataArray;
    this.category = {};
    this.listObjectMap = {}; // each category with it's List.js object
}

CategoryController.prototype = {
    curGroupBy: "groupId",
    curSortBy: "asc",
    dataArray: [],
    categories: {},
    init: function (options) {
        this.groupBy(this.curGroupBy);
        this.render(options);
        
		var self = this; 
    }
};
controller = new CategoryController(orignalData);
controller.init(options);

Open in new window

It seems to work for me bar the errors about groupBy() not being defined.
Thanks for your reply,
groupBy is already defined , I just remove it to make code simple.

In face  I call
controller = new CategoryController(orignalData);
controller.init(options);

Open in new window

from onclick function.

Also The error raised only when I change jquery from 2.1.1 to 3.1.1.
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial