选项1:
<script>
var myObject = function(){
this.iAm = 'an object';
this.whatAmI = function(){
alert('I am ' + this.iAm);
};
}
var myNewObject = new myObject();
myNewObject.whatAmI();
</script>
选项 2:
<script>
function myObject(){
this.iAm = 'an object';
this.whatAmI = function(){
alert('I am ' + this.iAm);
};
};
var myNewObject = new myObject();
myNewObject.whatAmI();
</script>
问题:
这两个代码都可以工作。但是它们之间有什么区别呢?在进行OOP
编码时,哪种方式更好js
?