Solved

jquery 3 and protoype

Posted on 2016-10-07
9
34 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
  • 4
  • 4
9 Comments
 
LVL 51

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
 
LVL 51

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

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

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 51

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now