Use below code for creating a java script counstruct:-
<script type="text/javascript">
var color = 'black';
function Box() {
// private property
var color = '';
// private constructor
__construct = function () {
alert("Object Created.");
color = 'green';
} ()
// getter
this.getColor = function () {
return color;
}
// setter
this.setColor = function (data) {
color = data;
}
}
var b = new Box();
alert(b.getColor()); // should be green
b.setColor('orange');
alert(b.getColor()); // should be orange
alert(color); // should be black
</script>
Liked By
Write Answer
JavaScript Construct?
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy
Join MindStick Community
You have need login or register for voting of answers or question.
AVADHESH PATEL
29-Jan-2013Hi Ankita Pandey!
Use below code for creating a java script counstruct:-
<script type="text/javascript">
var color = 'black';
function Box() {
// private property
var color = '';
// private constructor
__construct = function () {
alert("Object Created.");
color = 'green';
} ()
// getter
this.getColor = function () {
return color;
}
// setter
this.setColor = function (data) {
color = data;
}
}
var b = new Box();
alert(b.getColor()); // should be green
b.setColor('orange');
alert(b.getColor()); // should be orange
alert(color); // should be black
</script>