Learning JS is a bumpy road... I'd like to understand what happens inside my code, so console.log();
seems to be my friend.
From time to time I don't even know where errors came from (or I might be just too dumb) So I thought of better logging my app stack. I tried to find a answer for this simple yet complicated problem :
How to do that? Besides with console.log()
For example getting the name of a function (constructor) where the console.log
is being called proved problematic:
function SomeFunction(argument1,argument2) {
console.log(this+'> 01 message');
console.log(this.name+'> 02 message');
console.log(this.constructor+'> 03 message');
console.log(this.constructor.name+'> 04 message');
console.log(this.prototype+'> 05 message');
console.log(this.constructor.method+'> 06 message');
}
SomeFunction.prototype.sayHello = function(} {
console.log(this+'> 01 says Hello');
console.log(this.name+'> 02 says Hello');
console.log(this.constructor+'> 03 says Hello');
// and so on... //
}
So. Which one is Correct? SomeFunction.constructor.name
is working, but this syntax is quite long to use everytime, so something like
var fn = this.constructor.name
makes sense, but thats just inefficient.
Can someone point me into the good practices direction, how do I squeeze the right log info from my code?
FYI : I searched into several books about this simple topic, and neither one says anything about it.
Use developer tools (F12, control-I) or get firebug and enjoy single-stepping thru your code, examining and altering variables, editing css. it will improve your javascript learning experience dramatically...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.