Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Overriding Ractive prototype function 'sort' without calling the '/\b_super\b/' method can be very dangerous." #3301

Open
dzg opened this issue Apr 10, 2019 · 1 comment

Comments

@dzg
Copy link

dzg commented Apr 10, 2019

I'm new to ractive and looking at the table sort tutorial at https://ractive.js.org/tutorials/iterative-sections/#step-5

I see this in my console: Overriding Ractive prototype function 'sort' without calling the '/\b_super\b/' method can be very dangerous.

Am I doing something wrong?

@dzg dzg changed the title Overriding Ractive prototype function 'sort' "Overriding Ractive prototype function 'sort' without calling the '/\b_super\b/' method can be very dangerous." Apr 10, 2019
@fskreuz
Copy link
Contributor

fskreuz commented Apr 10, 2019

Ractive instances have a method called .sort on the prototype. When the code does this:

ractive = new Ractive({
  target: '#target',
  template: '#template',
  data: { superheroes: xmen },
  sort: function( column ) {
  	alert( 'Sorting by' + column )
  }
});

It's creating an instance using the passed object as config. Certain properties become configuration for the instance (target, template, data), while the rest become instance properties and methods (sort).

Since sort is on the instance and is visible earlier on the prototype chain, it will "shadow" the sort method on the prototype. So whenever you call sort, it calls this method instead of the sort on the prototype.

If you know what you're doing, and you intend to replace sort for this instance, you can ignore the warning. But if you intend to extend sort, you'd call _super in your sort so that it calls the built-in sort in addition to running your version of sort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants