Skip to content

Instantly share code, notes, and snippets.

@brendalong
Created July 23, 2018 12:21
Show Gist options
  • Save brendalong/7400039997c335e3fa116c65ba213bfe to your computer and use it in GitHub Desktop.
Save brendalong/7400039997c335e3fa116c65ba213bfe to your computer and use it in GitHub Desktop.
create object notes
const veryImportantInfo = {
"socialSecurity": "934-11-0201",
"bankAccountNumber": "4483271255",
"bankRoutingNumber": "458979043"
}
const requestFunds = function (customerInfo) {
// Note: Banks require that the account number and routing number be combined into a single value
customerInfo.bankAccountNumber = customerInfo.bankAccountNumber + customerInfo.bankRoutingNumber
const transactionInfo = customerInfo.bankAccountNumber
// Awesome code that performs the transaction goes here...
}
requestFunds(veryImportantInfo)
console.log(veryImportantInfo.bankAccountNumber) // 4483271255458979043 --> Yikes!
const safeImportantInfo = Object.create(null, {
socialSecurity: {
value: "934-11-0201",
writable: false
},
bankAccountNumber: {
value: "4483271255",
writable: false
},
bankRoutingNumber: {
value: "458979043",
writable: false
}
})
safeImportantInfo.socialSecurity = "haxx0r attack"
console.log(safeImportantInfo.socialSecurity) // 934-11-0201 --> It didn't change!
var user = {
sayHello: function() {
console.log('Hello '+ this.name);
}
};
var bob = Object.create(user, {
'id' : {
value: "444-66-7777",
enumerable:true // writable:false, configurable(deletable):false by default
},
'name': {
value: 'Bob',
enumerable: true
}
});
bob.sayHello();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment