Jump to content

Javascript Equivilant


madsovenielsen
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...