Skip to content

Instantly share code, notes, and snippets.

@ethaizone
Created September 12, 2016 11:27
Show Gist options
  • Save ethaizone/34ba96ad182f806c8308c6b2229bf97b to your computer and use it in GitHub Desktop.
Save ethaizone/34ba96ad182f806c8308c6b2229bf97b to your computer and use it in GitHub Desktop.
Short note
// Create class
function Cart(){
// constructur
// protected variable
var myProtected = 'secret';
// protected method
var protectedFunction = function() {
};
// method
this.get = function() {
protectedFunction();
return myProtected;
};
this.set = function(newSecret) {
myProtected = newSecret;
};
}
var myCart = new Cart;
myCart.set('my new secret');
console.log(myCart.get());
/////////////
// self execute function
(function(msg){
console.log(msg);
})('xxx');
/////////////
// .bind and .call
function My(msg) {
console.log(this);
console.log(msg);
}
var MyGotBinded = My.bind({name: 'John'}, 'xxx');
MyGotBinded();
My.call({name: 'JohnAA'}, 'xxxAAA');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment