Solved

jquery 3 and protoype

Posted on 2016-10-07
9
61 Views
Last Modified: 2016-10-18
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
0
Comment
Question by:ethar1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 57

Expert Comment

by:Julian Hansen
ID: 41834700
That error does not look like it pertains to the snippet you have posted.
0
 

Author Comment

by:ethar1
ID: 41834716
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

0
 

Author Comment

by:ethar1
ID: 41834747
Error raised :
PropertiesWindow.js:63 Uncaught TypeError: controller.init is not a function
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 57

Expert Comment

by:Julian Hansen
ID: 41834755
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

0
 

Author Comment

by:ethar1
ID: 41834928
what about the code I sent?
0
 
LVL 57

Expert Comment

by:Julian Hansen
ID: 41834949
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.
0
 

Author Comment

by:ethar1
ID: 41834959
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.
0
 
LVL 57

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 41834996
In my sample above I am running JQuery 3.1.1 - I don't get the error you are getting. The only error I get is the groupBy is missing. If I add those in - no issues. So I am guessing there is something else happening.

My working code
<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);
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: {},
	groupBy: function(gb) {
		console.log(gb);
	},
	render: function(options) {
		console.log(options);
	},
    init: function (options) {
        this.groupBy(this.curGroupBy);
        this.render(options);
        
		var self = this; 
    }
};
controller = new CategoryController(x);
var options = {};
controller.init(options);
</script>

Open in new window

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question