Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am asking this question because it is difficult to search/google it.
Sometimes in javascript, I want to debug things. I am writing alert(var); or console.log(variable); but very often I get something like this:
[object][Object]
If I don't know what object it is I have hard time guessing what properties it has. What are ways of painless debugging this type of objects? And by the way, what debugging methods do you recommend?
I know it is duplication, sorry for this. Answers I found so far were not satisfying.
edit
myObj = {myObjProp: objVal}
Ok. alert(myObj); => [object][object]. Is there a method that would allow me to alert a real object like alert(exampleMethod(myObj)); => {myObjProp: objVal} ?
If you use alert to print an object, then that object would be converted into a primitive value (string) before displaying. So for instance toPrimitive({}) would be [object Object]. That is why you have to use console.log(object) while debugging your code.
Just use the debugger statement.
and access it from the console
function potentiallyBuggyCode() {
debugger;
// do potentially buggy stuff to examine, step through, etc.
}
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed last month.
Improve this question
I want to call this method named 'prototype' but I don't know how to call it.(last method)
enter image description here
how should I call this method?
I tried .[[Prototype]] .Prototype .prototype and ...
You can access the Prototype property like so:
Object.getPrototypeOf(myObject)
Make sure myObject is defined before you call this.
See https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object_prototypes for more information.
If you are not expecting the Prototype property in this object, please describe what your code is doing and provide snippets related to the bug.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have in my JS code, some lines with binde, what is it? Why is it working and what does it mean?
On example with, type="checkbox":
if (document.binde.nameofthecheckbox.checked)
{
//...its true whens checked and do the code
}
or
somevar = document.binde.somehtmltagname.value;
somevar gets the value of "somehtmltagname"
No one can answer me, I only heard "never seen something like that before". I would be happy to know what it is, and not only using it because it works.
It is not well known, but document might define HTML elements with id specified as document[HTMLElement.ID] as such, if there is an <input id="binde"> on the page, it will point to that.
If not, try logging it:
console.log(document.binde)
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I looked below code in blog cause i wanna know about this.
When i copy & paste this code and then execute that.
The result is different.
The result of bike is undefined. But i dont know why result is different.
That is so because , global scope in browser and nodejs are different. When you declare a var in browser , variable is attached to global scope and can be accessed by this operator. Where as it is not the case with nodejs.
So if you copy paste and run this code in browser it would work as expected.
More clarification
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I m working with balloon pop up which will invoke for currently running test case, I need to pass the current test case name to that balloon popup.I tried with browser.currentTest but it is returning [object, object]. Is there any other way of retrieving the current test case name,if so can someone help me in retrieving the current test case name. Thanks in advance.
Try
browser.currentTest.module
In nightwatch, you have access to the name of the currentTest using .module. It's not in the docs, it just came up by logging
var keys = Object.keys(client.currentTest)
to the console like:
console.log(keys)
from the base test class. Adding that to the prototype isn't even necessary as it's available in any test. "module" is a property of the Test object in Nightwatch.
Also note that, from experience, the seemingly inaptly named browser.currentTest.name is not what you want. It's an array of numbers whose purpose I have yet to deduce...
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Sometimes it occurs that I like a feature on an page and want to read its javascript,
but it is an difficult task to manually find where the function is especially when the webpages more than one js files.
Is there a way I can get/copy the only required js file by its name which I can easily get by inspecting page.
examole:
<div id='abc()'></div>
Now how to fine the source of function div()?
The simplest solution for a function which is defined in the global scope :
open the console of your browser (F12 in most browsers)
type the name of the function
For example type klass in the console on this page.
In the general case, you really need to learn to use the console, including the debugger.
Regarding your practical question : what changes the background of the http://www.noisli.com/ page :
it's not the changebackground function : this function doesn't exist
it's in the first line of jplayer.js
But the way I found it is too hacky, I hacked the Math.random function by typing this in the console :
Math.random = function(){ debugger; return Math.random() }
so that I would enter in debug and see the call stack...
I hope somebody can propose a clean way.
If you can execute boormakrlets in your address-bar, you could do:
javascript:abc.toString()
Or better:
javascript:alert(abc.toString())