Quote:
Originally Posted by Sylvain_
Thanks for the instanceof hint. My code doesn't really look weird to me, the only things is that is not really the javascript way, which I consider as positive.
|
Oh, I didn't mean your code I mean DaveyErwin's example .
Quote:
Originally Posted by DaveyErwin
Because they are teaching the javascript way,
not the C# or Java way.
this looks more javaScriptish to me …
Code:
<script>
function addItem(i){
i.dinc();
this.totalCash = "$"+(Number(this.totalCash.split("$")[1]) + Number(i.unitPrice.split("$")[1])).toFixed(2);
this.items.push({name:i.name,unitPrice:i.unitPrice,catagory:i.catagory,numOnhand:i.numOnhand,regTotcash:this.totalCash});
}
function dinc(){
--this.numOnhand
}
Register = {totalCash:"$100.00",items:[],addItem:addItem}
var cola = {name:"cola",unitPrice:"$1.28",catagory:"drinks",numOnhand:24,dinc:dinc};
tea = {name:"tea",unitPrice:"$3.99",catagory:"drinks",numOnhand:16,dinc:dinc};
Register.addItem(cola);
Register.addItem(tea);
//!price of cola goes up!
cola.unitPrice = "$1.39";
Register.addItem(cola);
Register.addItem(tea);
var ri = Register.items;
for (var i = 0; i < ri.length; i++) {
document.writeln("this sale ",ri[i].name,ri[i].unitPrice," you have ",ri[i].numOnhand," left your register has ",ri[i].regTotcash,"<br>");
}
</script>
|
As someone who run around .Net framework since version 2.0, I could say propotype of javascript is something really amazing that .Net framework will never has it even if you use MSIL.
If you like OOP concept, I suggest you study about real concept of OOP, not just their formation. After you understand OOP concept's purpose, you should study about Refactoring. If you can master these thing, your will coding OOP style in almost language like you breath