Published
Edited
Jul 12, 2018
10 stars
Insert cell
Insert cell
Insert cell
Insert cell
{
const person = {
name: 'Mateusz',
lastnme: 'Choma',
sayHello: function (){
console.log('Hello ' + this.name + ' ' + this.lastname)
}
}
return person
}
Insert cell
Insert cell
Insert cell
{
const makePerson = function(name, lastname){
return {
name: name,
lastname: lastname,
sayHello: function (){
console.log('Hello ' + this.name + ' ' + this.lastname)
}
}
}
return makePerson('Jan', 'Kowalski')
}
Insert cell
Insert cell
{
const makePerson = function(name, lastname){
return {
name: name,
lastname: lastname,
sayHello: function (){
console.log('Hello ' + this.name + ' ' + this.lastname)
}
}
}
const person1 = makePerson('Jan', 'Kowalski')
const person2 = makePerson('Janina', 'Kowalska')
return person1.sayHello === person2.sayHello
}
Insert cell
{
const sayHello = function (){
console.log('Hello ' + this.name + ' ' + this.lastname)
}
const makePerson = function(name, lastname){
return {
name: name,
lastname: lastname,
sayHello: sayHello
}
}
const person1 = makePerson('Jan', 'Kowalski')
const person2 = makePerson('Janina', 'Kowalska')
return person1.sayHello === person2.sayHello
}
Insert cell
{
const createMakePerson = function() {
const sayHello = function (){
console.log('Hello ' + this.name + ' ' + this.lastname)
}

const makePerson = function(name, lastname){
return {
name: name,
lastname: lastname,
sayHello: sayHello
}
}
return makePerson
}
const makePerson = createMakePerson()
const person1 = makePerson('Jan', 'Kowalski')
const person2 = makePerson('Janina', 'Kowalska')

return person1.sayHello === person2.sayHello
}
Insert cell
Insert cell
{
const objectThatWillBeAPrototype = {
sayHello: function (){
return 'Hello ' + this.name + ' ' + this.lastname
}
}

const newObject = Object.create(objectThatWillBeAPrototype)
return newObject.sayHello()
}
Insert cell
{
const objectThatWillBeAPrototype = {
sayHello: function (){
return 'Hello ' + this.name + ' ' + this.lastname
}
}

const newObject = Object.create(objectThatWillBeAPrototype)
newObject.name = 'Mateusz'
newObject.lastname = 'Choma'
return newObject.sayHello() // newObject doesent have own property 'sayHello' it is in prototype!
}
Insert cell
Insert cell
{
const obj1 = {
name: 'Ala'
}

const obj2 = {
name: 'Ela',
lastname: 'Kowalska'
}
Object.assign(obj1, obj2) // it return obj1
return obj1
}
Insert cell
{
return {
name: 'Ala',
name: 'Ela',
lastname: 'Kowalska'
}
}
Insert cell
{
const obj1 = {
name: 'Ala'
}

const obj2 = {
name: 'Ela',
lastname: 'Kowalska'
}
const obj3 = Object.assign({}, obj1, obj2) // it return obj1
return obj3
}
Insert cell
Insert cell
{
function Person(name, lastname){
this.name = name
this.lastname = lastname
}
const person = new Person('Mateusz', 'Choma')
console.log(person)
return person
}
Insert cell
{
function Person(name, lastname){
this.name = name
this.lastname = lastname
}
const person = Person('Mateusz', 'Choma')
return person
}
Insert cell
{
function Person(name, lastname){
this.name = name
this.lastname = lastname
}
Person.prototype.sayHello = function (){
return 'Hello ' + this.name + ' ' + this.lastname
}
const person1 = new Person('Jan', 'Kowalski')
console.dir(Person)
console.log(person1)
console.log(Person.prototype === person1.__proto__)
return person1.sayHello()
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more