javascript - jquery is not functional? -


this question has answer here:

firefox (v52.0), jquery

this works:

// example 1 $('html').find('body') 

this works:

// example 2 var h h=$('html') h.find('body') 

this doesn't work:

// example 3 var f f=$('html').find f('body') 

i

error: permission denied access property "ownerdocument"

why?

but works:

// example 4 var a = x => $('html').find(x) a('body') 

example 3 doesn't work because find called on global context when assign f. if use call , pass in valid jquery object context, code works. try

var f = $('html').find;  console.log(f.call($('html'), 'body').length)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

also, example 4 works because a can translated following code, if written without arrow function.

var = function(x) {   return $('html').find(x); }; 

it's example 1, wrapper function in order take parameter


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -