From 214972888ecd642f7bbe8c123e5da67a87ce0823 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Tue, 19 Aug 2014 19:25:50 -0400 Subject: [PATCH] Return a fully-qualified Function from `$.load` The function generated by `$.load` should inherit from the `Function` prototype so that methods like `call`, `apply`, and `bind` are available to users. --- lib/static.js | 2 +- test/cheerio.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/static.js b/lib/static.js index 1e525a0712..858e39abc9 100644 --- a/lib/static.js +++ b/lib/static.js @@ -28,7 +28,7 @@ exports.load = function(content, options) { initialize.prototype = Cheerio.prototype; // Add in the static methods - initialize.__proto__ = exports; + _.merge(initialize, exports); // Add in the root initialize._root = root; diff --git a/test/cheerio.js b/test/cheerio.js index 46944ea68d..954d54a453 100644 --- a/test/cheerio.js +++ b/test/cheerio.js @@ -284,5 +284,11 @@ describe('cheerio', function() { expect(domEncoded('footer').html()).to.be(expectedXml); }); + it('should return a fully-qualified Function', function() { + var $c = $.load('
'); + + expect($c).to.be.a(Function); + }); + }); });