Created
September 12, 2016 11:27
-
-
Save ethaizone/34ba96ad182f806c8308c6b2229bf97b to your computer and use it in GitHub Desktop.
Short note
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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