'find', 'attr', possibly more methods are undefined in .map 'this' context.
See original GitHub issueCalling this.find('...')
, this.attr('...')
throws a TypeError: Object #<Object> has no method ...
error when called in the context of .map
.
Example:
var $ = require('cheerio').load(
'<ul>'
+ '<li><a href="/1">1</a></li>'
+ '<li><a href="/2">2</a></li>'
+ '<li><a href="/3">3</a></li>'
+ '<li><a href="/4">4</a></li>'
+ '</ul>'
);
// Works
console.log($('li').eq(0).find('a').attr('href'));
// Fails with:
// return this.find('a').attr('href');
// ^
// TypeError: Object #<Object> has no method 'find'
console.log($('li').map(function () {
return this.find('a').attr('href');
}));
This worked in cheerio 0.12.4 and fails in 0.13.1
Issue Analytics
- State:
- Created 10 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Typescript: Object is possibly 'undefined' - Stack Overflow
There are two ways to that I can think of to get rid of the error. The first way I can think of...
Read more >Maps JavaScript API | Google Developers
For vector maps, this method sets the map's tilt and heading to their default zero ... If the map is not yet initialized...
Read more >How to Read React Errors (fix 'Cannot read property of ...
Cannot read property `map` of undefined. In this post we'll talk about how to fix this one specifically, and along the way you'll...
Read more >CoffeeScript
The JavaScript arguments object is a useful way to work with functions that accept variable numbers of arguments. CoffeeScript provides splats ... ,...
Read more >OpenLayers v7.2.2 API - Class: Map
The constructor places a viewport container (with CSS class name ol-viewport ) in the target element (see getViewport() ), and then two further...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi Aleksey,
The change you’ve reported is intentional because it more closely mimics jQuery. Just like in jQuery, the context of the callback function is the node. If you’d like to use the Cheerio API, then you can create a new Cheerio object with the node:
Does this work for you?
yah, there’s lots of things i’d like to change about jquery. check out the client-side component/dom for some of those ideas.