Corso Data Journalist gen-mar 2017
TECNOLOGIE WEB BASE
Oggetti
var BOY= new Object()
var BOY= {}
BOY.AGE=10;
BOY['HEIGHT']=1.20;
BOY.SayHello= function(){console.log('Hello')};
BOY.Say=function(W){console.log(W,W,W)};
var BOY = {
'AGE':12,
'HEIGHT': 1.45,
NAME: 'Jonh',
'SayHello':
function(){console.log('Hello')},
'Say':
function(W){console.log(W,W,W)},
}
Costruzione di un oggetto
tramite notazione letterale
Medesima sintassi di utilizzo attributi e metodi
BOY[‘AGE’] oppure BOY.AGE
BOY[‘SayHello’]() oppure BOY.SayHello()
tramite costruttore Object o {}
Costruzione di un oggetto tramite function
function BOY() {}
BOY.AGE=12;
BOY.HEIGHT= 1.45;
BOY.NAME= ‘Jonh’;
BOY.SayHello= function(){console.log('Hello')};
BOY.Say=function(W){console.log(W,W,W)};
function BOY() {
AGE=12;
HEIGHT= 1.45;
NAME= 'Jonh';
SayHello= function(){console.log('Hello')};
Say=function(W){console.log(W,W,W)};
}
function BOY() {
AGE:12,
HEIGHT: 1.45,
NAME: 'Jonh',
SayHello: function(){console.log('Hello')},
Say:function(W){console.log(W,W,W)},
}
ERRORE
ALTRO
SIGNIFICATO
La parola chiave this
nella notazione letterale
var BOY= new Object()
var BOY= {}
BOY.AGE=10;
BOY.HEIGHT=1.20;
BOY.SayHello= function(){console.log(this.AGE)};
BOY.Say=function(W){console.log(W,W,W)};
nel costruttore Object / {}
BOY = {
'AGE':12,
'HEIGHT': 1.45,
‘SayHello': function(){console.log(this.AGE)},
‘Say':function(W){cvaronsole.log(W,W,W)},
}
in un oggetto costruito tramite function (crea un prototipo di oggetto)
function BOY() {
this.AGE=12;
this.HEIGHT= 1.45;
}
prototipo di oggetti
var MF = new Person("John", "Doe", 50, "blue");
var MM = new Person("Sally","Rally", 48, "green");
function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye; }
Costruzione Utilizzo
Risultato
MF { firstName: 'John', lastName: 'Doe', age: 50, eyeColor: 'blue' }
MM { firstName: 'Sally', lastName: 'Rally', age: 48, eyeColor: 'green' }
sintassi a catena
function Boy(NAME, SURNAME, GENDER, AGE) {
this.name = NAME;
this.surname = SURNAME;
this.gender = GENDER;
this.age = AGE;
this.setName = function(x) {this.name = x; return this;};
this.setSurname = function(x) {this.surname = x; return this;};
this.setAge = function(x) {this.age= x; return this;};
this.setGender = function(x) {this.gender = x; return this;}; }
funzione Boy
attributi
metodi
oggetti MYSON1
MYSON2
var MYSON1=new Boy('John','Smith','male',11);
var MYSON2=MYSON1;
MYSON2.setName('Paul')
.setAge(8) ;
Oggetti Javascript e python
Javascript Python
class UNO():
def __init__(self,X,Y):
self.X=X
self.Y=Y
def Show(self):
print('Questa è la variabile X: ',self.X)
print('Questa è la variabile Y: ',self.Y)
A=UNO(10,20)
A.Show()
Questa è la variabile X: 10
Questa è la variabile Y: 20
function UNO(X,Y) {
this.X=X;
this.Y=Y;
this.Show=function(){
console.log('Questa è la variabile X: ',this.X);
console.log('Questa è la variabile Y: ',this.Y); }
}
var A =new UNO(10,20);
A.Show()
Questa è la variabile X: 10
Questa è la variabile Y: 20
LEZIONE 1..
www.fordatascientist.org
D00-Web-JsBase
D14-Nodejs-Object.ipynb
CONTATTI TELEFONO
051 22 35 20
EMAIL
WORKSHOP@VICEM.IT

Web base-05-js-object

  • 1.
    Corso Data Journalistgen-mar 2017 TECNOLOGIE WEB BASE Oggetti
  • 2.
    var BOY= newObject() var BOY= {} BOY.AGE=10; BOY['HEIGHT']=1.20; BOY.SayHello= function(){console.log('Hello')}; BOY.Say=function(W){console.log(W,W,W)}; var BOY = { 'AGE':12, 'HEIGHT': 1.45, NAME: 'Jonh', 'SayHello': function(){console.log('Hello')}, 'Say': function(W){console.log(W,W,W)}, } Costruzione di un oggetto tramite notazione letterale Medesima sintassi di utilizzo attributi e metodi BOY[‘AGE’] oppure BOY.AGE BOY[‘SayHello’]() oppure BOY.SayHello() tramite costruttore Object o {}
  • 3.
    Costruzione di unoggetto tramite function function BOY() {} BOY.AGE=12; BOY.HEIGHT= 1.45; BOY.NAME= ‘Jonh’; BOY.SayHello= function(){console.log('Hello')}; BOY.Say=function(W){console.log(W,W,W)}; function BOY() { AGE=12; HEIGHT= 1.45; NAME= 'Jonh'; SayHello= function(){console.log('Hello')}; Say=function(W){console.log(W,W,W)}; } function BOY() { AGE:12, HEIGHT: 1.45, NAME: 'Jonh', SayHello: function(){console.log('Hello')}, Say:function(W){console.log(W,W,W)}, } ERRORE ALTRO SIGNIFICATO
  • 4.
    La parola chiavethis nella notazione letterale var BOY= new Object() var BOY= {} BOY.AGE=10; BOY.HEIGHT=1.20; BOY.SayHello= function(){console.log(this.AGE)}; BOY.Say=function(W){console.log(W,W,W)}; nel costruttore Object / {} BOY = { 'AGE':12, 'HEIGHT': 1.45, ‘SayHello': function(){console.log(this.AGE)}, ‘Say':function(W){cvaronsole.log(W,W,W)}, } in un oggetto costruito tramite function (crea un prototipo di oggetto) function BOY() { this.AGE=12; this.HEIGHT= 1.45; }
  • 5.
    prototipo di oggetti varMF = new Person("John", "Doe", 50, "blue"); var MM = new Person("Sally","Rally", 48, "green"); function Person(first, last, age, eye) { this.firstName = first; this.lastName = last; this.age = age; this.eyeColor = eye; } Costruzione Utilizzo Risultato MF { firstName: 'John', lastName: 'Doe', age: 50, eyeColor: 'blue' } MM { firstName: 'Sally', lastName: 'Rally', age: 48, eyeColor: 'green' }
  • 6.
    sintassi a catena functionBoy(NAME, SURNAME, GENDER, AGE) { this.name = NAME; this.surname = SURNAME; this.gender = GENDER; this.age = AGE; this.setName = function(x) {this.name = x; return this;}; this.setSurname = function(x) {this.surname = x; return this;}; this.setAge = function(x) {this.age= x; return this;}; this.setGender = function(x) {this.gender = x; return this;}; } funzione Boy attributi metodi oggetti MYSON1 MYSON2 var MYSON1=new Boy('John','Smith','male',11); var MYSON2=MYSON1; MYSON2.setName('Paul') .setAge(8) ;
  • 7.
    Oggetti Javascript epython Javascript Python class UNO(): def __init__(self,X,Y): self.X=X self.Y=Y def Show(self): print('Questa è la variabile X: ',self.X) print('Questa è la variabile Y: ',self.Y) A=UNO(10,20) A.Show() Questa è la variabile X: 10 Questa è la variabile Y: 20 function UNO(X,Y) { this.X=X; this.Y=Y; this.Show=function(){ console.log('Questa è la variabile X: ',this.X); console.log('Questa è la variabile Y: ',this.Y); } } var A =new UNO(10,20); A.Show() Questa è la variabile X: 10 Questa è la variabile Y: 20
  • 8.
  • 9.
    CONTATTI TELEFONO 051 2235 20 EMAIL WORKSHOP@VICEM.IT