Jump to content

Javascript Equivilant


madsovenielsen

Recommended Posts

Hey all.I am wondering what the JavaScript equivilant of this piece of Java is:

  // Create_account creates an account, deposits money, and returns an account  public account create_account(double balance)  {	 account my_account;	 // Instantiate a new object	 my_account = new account(balance);	 // Call the deposit method of our object my_account	 my_account.deposit(25.00);	 return account;  }

Any help / code snippets will be greatly appriciated/mads

Link to comment
Share on other sites

Something like this (sample account() shown for clarity):

var account = function(balance) {	this.b = balance;	this.deposit = function(n) {		this.b += n;	}	this.show = function() {		alert(this.b);	}}var create_account = function(balance) {	var my_account = new account(balance);	my_account.deposit(25);	return my_account; //should be my_account in Java version too!}var test = create_account(25);test.show();

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...