Hey guys, here I am starting my journey into javascript, when this stupid bug is annoying me. Following is my piece of code:
<html>
<head>
<title> Using 'this' in Javascript.</title>
</head>
<body>
<script type="text/javascript">
var name={
firstName:"Foo",
lastName:"Bar",
showName:function(){
console.log(this.firstName +" "+this.lastName);
}
};
name.showName();
alert(name.lastName);
</script>
</body>
</html>
Problems:
1) I am getting following error for name.showName();'
Uncaught TypeError: undefined is not a function`
2) Undefined popup for alert(name.lastName)
As far as my knowledge takes me I have already defined object property and method before using.
Where do you guys think is the bug ?
Regards