Skip to content

Instantly share code, notes, and snippets.

@octosteve
Created May 31, 2016 16:06
Show Gist options
  • Save octosteve/6597b114d9b41f0358909ad9c303ee06 to your computer and use it in GitHub Desktop.
Save octosteve/6597b114d9b41f0358909ad9c303ee06 to your computer and use it in GitHub Desktop.
// // var me = {
// // name: "Steven",
// // sayHi: function(){
// // console.log(`Hi, my name is chicka chicka ${this.name}`);
// // }
// // }
//
// function Person(name){
// this.name = name
// this.friends = []
// }
//
// Person.prototype.sayHi = function () {
// console.log(`Hi, my name is chicka chicka ${this.name}`);
// };
//
// Person.prototype.addFriend = function (friendName) {
// this.friends.push(friendName)
// };
//
// Person.prototype.greetFriends = function () {
// // var _that = this
// // var you = {name: "An Axe Murderer"}
// var callback = function(friend){
// console.log(`${this.name} says hi to ${friend}`);
// }
//
// var boundCallback = callback.bind(this)
// var method = this.greetFriend
//
// this.friends.forEach(callback, this)
// this.friends.forEach(boundCallback)
// this.friends.forEach(method)
// };
//
// Person.prototype.greetFriend = function (friend) {
// console.log(`${this.name} says hi to ${friend}`);
// };
var Person = {
init: function(name){
function sayHi(){
console.log(`Hi, it's ${this.name}`);
}
return {
name: name,
sayHi: sayHi
}
}
}
var me = Person.init("Steven")
// me.addFriend("Sophie")
// me.addFriend("Antoin")
// me.greetFriends()
me.sayHi()
// var sayThis = function sayThis(){
// console.log(this)
// }
// // sayThis()
//
// var observer = {
// info: "I am observer... Raarrrr",
// sayThis: sayThis
// }
//
// observer.sayThis()
// sayThis()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment