This is fragment of a JS plugin that I'm using on my site. I'd like to inspect the value of isTouchDevice
directly in the console. Just typing isTouchDevice
reurns an 'undefined' error.
(function($) {
"use strict";
$.maxmegamenu = function(menu, options) {
var plugin = this;
var $menu = $(menu);
plugin.settings = {};
var isTouchDevice = function() {
return ('ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0);
};
})(jQuery);
How I can inspect the value of isTouchDevice
variable in Chrome console?
Edit 1:
To clarify, First, I need to be able to inspect the value of var isTouchDevice
directly in the console, without adding any code. Second, console.log(isTouchDevice)
would return an 'undefined error' probably due to the variable encapsulation (it's not available in the global scope) so just console-logging it is not a way to go.
This is fragment of a JS plugin that I'm using on my site. I'd like to inspect the value of isTouchDevice
directly in the console. Just typing isTouchDevice
reurns an 'undefined' error.
(function($) {
"use strict";
$.maxmegamenu = function(menu, options) {
var plugin = this;
var $menu = $(menu);
plugin.settings = {};
var isTouchDevice = function() {
return ('ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0);
};
})(jQuery);
How I can inspect the value of isTouchDevice
variable in Chrome console?
Edit 1:
To clarify, First, I need to be able to inspect the value of var isTouchDevice
directly in the console, without adding any code. Second, console.log(isTouchDevice)
would return an 'undefined error' probably due to the variable encapsulation (it's not available in the global scope) so just console-logging it is not a way to go.
-
2
For simplicity, you can just run
('ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0)
in the chrome console. Otherwise you can put a breakpoint after declaration and add a watch in your dev tools – CodingIntrigue Commented Jun 3, 2015 at 15:03 - note that isTouchDevice in your code snippet is assigned with a function. to get the value you need to access it by invoking it console.log(isTouchDevice()); you also need to call it in the right scope which is inside the block var isTouchDevice is declared – lid Commented Jun 3, 2015 at 15:06
- @RGraham, this is a great remendation which solves my problem - executing the expression directly in the console.. – luqo33 Commented Jun 3, 2015 at 20:07
-
@lid Just out of curiousity as my probelm has already been solved. Due to scoping, I will not be able to inspect
isTouchDevice()
directly in the console? – luqo33 Commented Jun 3, 2015 at 20:08 - @luqo33, that is right, to have access to the method you need to be in the right scope chain. see: gist.github./anonymous/db528b893d477b49775a hypothetically if you need to run arbitrary code within a particular scope/conext in console, the approach eck mentioned is the way to go about it. – lid Commented Jun 3, 2015 at 23:11
2 Answers
Reset to default 3You can also add a debugger;
statement at the end of your maxmegamenu function.
When chrome breaks on that statement the console will be within the context of that function and isTouchDevice
should be defined then.
Use console.log(isTouchDevice);
or other console
methods like
.info
.warn
.error
.debug
or you can use grouping with console.group('this is some event');
then close group with console.groupEnd();
last method is console.groupCollapsed('some title of group');
, what will create group, but will be collapsed in console, consuming less space