Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialtoddschneider
4,795 Pointsis it possible to turn console.log() into a variable or Function?
is it possible to turn console.log() into a variable or Function. that could be called on a shorter name like logIt ?
so far all my attempts have failed.
4 Answers
Dustin Scott
Courses Plus Student 7,819 PointsI did like this and it worked
<script>
function logit(value){
console.log(value);
}
logit("something");
</script>
Tell me if it works with you
Carie Andy Tugano
46 PointsI am not sure if this is what you want to achieve, but you may check this out.
Put this at the top of the file: var console = {}; console.log = function(){}; For some browsers and minifiers, you may need to apply this onto the window object. window.console = console;
Source: http://stackoverflow.com/questions/7042611/override-console-log-for-production
James Barnett
39,199 PointsSure it is, you can even get console.log output to your screen, useful for using codepen while learning JS.
toddschneider
4,795 PointsThanks Every one! All of your guy's advice worked out very well. Now I am able to simplify a lot of of this code. my original code I was building was really close to Dustin's answer but no cigar.
function logit (inFo) {
logit = console.log(inFo);
}
thanks again guys !
toddschneider
4,795 Pointstoddschneider
4,795 PointsYes Dustin It worked perfect thanks a million.
Dustin Scott
Courses Plus Student 7,819 PointsDustin Scott
Courses Plus Student 7,819 PointsYou are welcome bro :)