Skip to content

Instantly share code, notes, and snippets.

@mattjmorrison
Last active December 10, 2015 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattjmorrison/4420940 to your computer and use it in GitHub Desktop.
Save mattjmorrison/4420940 to your computer and use it in GitHub Desktop.
// Instead of
Someframework.object.create({
my: 'attributes',
go: 'here'
});
// Try doing this
function MyObject(){
this.my = "attributes";
this.go = "here";
}
Someframework.object.create(new MyObject());
class Person
constructor: ->
@firstName = "Matt"
@lastName = "Morrison"
@numbers = [1, 2, 3, 4, 5]
@otherThings =
one: 1
two: 2
five: 5
doSomething: ->
"I'm working on it"
console.log(new Person().doSomething())
class Person:
def __init__(self):
self.first_name = "Matt"
self.last_name = "Morrison"
self.numbers = [1, 2, 3, 4, 5]
self.other_things = {'one': 1, 'two': 2, 'five': 5}
def do_something(self):
return "I'm working on it"
print Person().do_something()
# > "I'm working on it"
class Person
def initialize
@first_name = "Matt"
@last_name = "Morrison"
@numbers = [1, 2, 3, 4, 5]
@other_things = {:one => 1, :two => 2, :five => 5}
end
def do_something
"I'm working on it"
end
end
puts Person.new.do_something
# > "I'm working on it"
var Person;
Person = (function() {
function Person() {
this.firstName = "Matt";
this.lastName = "Morrison";
this.numbers = [1, 2, 3, 4, 5];
this.otherThings = {
one: 1,
two: 2,
five: 5
};
}
Person.prototype.doSomething = function() {
return "I'm working on it";
};
return Person;
})();
console.log(new Person().doSomething());
var person;
person = {
firstName: "Matt",
lastName: "Morrison",
doSomething: function() {
return "I'm working on it";
},
otherThings: {
five: 5,
one: 1,
two: 2
},
numbers: [1, 2, 3, 5, 4]
};
function Person(){
this.firstName = "Matt";
this.lastName = "Morrison";
this.numbers = [1, 2, 3, 4, 5];
this.otherThings = {one: 1, two: 2, five: 5};
}
Person.prototype.doSomething = function(){
return "I'm working on it";
};
console.log(new Person().doSomething());
// > "I'm working on it"
person =
firstName: "Matt"
lastName: "Morrison"
doSomething: ->
return "I'm working on it"
otherThings:
five: 5
one: 1
two: 2
numbers: [1, 2, 3, 5, 4,]
var person = {
firstName: "Matt",
lastName: "Morrison",
doSomething: function(){
return "I'm working on it";
},
otherThings: { // moved up a line
five: 5 // moved to first position
one: 1,
two: 2,
}
numbers: [1, 2, 3, 5 4,], // Moved 5 to 4th position
};
person = {
'firstName': "Matt",
'lastName': "Morrison",
'doSomething': lambda: "I'm working on it",
'numbers': [1, 2, 3, 4, 5,],
'otherThings': {
'one': 1,
'two': 2,
'five': 5,
},
}
print person['doSomething']()
# > "I'm working on it"
person = {
:firstName => 'Matt',
:lastName => 'Morrison',
:doSomething => lambda { "I'm working on it" },
:numbers => [1, 2, 3, 4, 5,],
:otherThings => {
:one => 1,
:two => 2,
:five => 5,
},
}
puts person[:doSomething].call
# > "I'm working on it"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment