Solved

jquery 3 and protoype

Posted on 2016-10-07
9
55 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

732 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