Option 1:
<script>
var myObject = function(){
this.iAm = 'an object';
this.whatAmI = function(){
alert('I am ' + this.iAm);
};
}
var myNewObject = new myObject();
myNewObject.whatAmI();
</script>
Option 2:
<script>
function myObject(){
this.iAm = 'an object';
this.whatAmI = function(){
alert('I am ' + this.iAm);
};
};
var myNewObject = new myObject();
myNewObject.whatAmI();
</script>
Question:
Both of these codes can work. But what is the difference between them? And which is the better way when doing OOP
coding in js
?