, , , y .
, -, , , :
function SomeClass(){
var y = 15;
}
... , .
, , , , , , y, y .
, :
<script type="text/javascript">
function SomeClass() {
var y = 15;
return {
getY : function() { return y },
setY : function(newY) { y = newY; }
};
};
var obj = new SomeClass();
function showY() {
alert("obj.getY: " + obj.getY());
}
function updateY() {
obj.setY(25);
alert("updated.");
}
</script>
<input type="button" onclick="showY();return false;" value="showY"/>
<input type="button" onclick="updateY();return false" value="updateY"/>
"showY", "updateY", "showY", .
This is not the only template that I personally use, but javascript is so flexible there are a lot of fun things you can do with it.
I hope I didn’t blow you up too much and hope this helps a bit with the concepts!
source
share