RcBuilder@walla.com
call centre: 054-5614020

OOP in javascript

Posted by: RcBuilder  /   Category: class / function / JAVASCRIPT / Object / OOP / prototype   /   No Comments
26
Jan
2016

custom Objects -------------- // Literal (a single instance) var person = { firstName: 'Roby', lastName: 'Cohen', sayYourName: function () { return this.firstName + ' ' + this.lastName; } }; console.log(person.sayYourName()); // Roby Cohen ---- // Factory (multiple instances) function PersonFactory(firstName, lastName) { return { firstName: firstName, lastName: lastName, sayYourName: function () { return this.firstName + ' ' + this.lastName; } }; } var person = PersonFactory('Roby', 'Cohen'); var person2 = PersonFactory('Avi', 'Cohen'); console.log(person.sayYourName()); // Roby Cohen console.log(person2.sayYourName()); // Avi Cohen ---- //.

Read more

javascript fixing the ‘new’ keyword

Posted by: RcBuilder  /   Category: class / function / JAVASCRIPT / Object / prototype   /   No Comments
26
Jan
2016

javascript fixing the lack of 'new' keyword when creating an instance of an object when creating an instance of the object and forget to use the 'new' keyword the 'this' variable will refer to the 'window' object. we can use this behavior to initialize a fresh instance of the current object and return it. this way we'll be able.

Read more

javascript instanceof

Posted by: RcBuilder  /   Category: class / function / JAVASCRIPT / Object / prototype   /   No Comments
26
Jan
2016

javascript instanceof structure: instanceof e.g: person instanceof Person using: function Person(Name) { this.Name = Name; } function Employer(Name) { this.Name = Name; } var person = new Person('Roby Cohen'); var employer = new Employer('Roby Cohen'); console.log(person instanceof Person); // true console.log(employer instanceof Person); // false console.log(employer instanceof Employer); // true if (person instanceof Person) console.log('PERSON : ' + person.Name); // PERSON : Roby Cohen notice! any class inherit from object therefore.

Read more

javascript callback fucntion

Posted by: RcBuilder  /   Category: Array / callback / class / function / JAVASCRIPT / Object / OOP   /   No Comments
26
Jan
2016

javascript callback fucntion function foreach(arr, callback) { for (var i = 0; i < arr.length; i++) callback.call(this, arr); } var arr = ; foreach(arr, function (item) { console.log(item); }); --- function fun1(callback) { setTimeout(callback, 2000); } console.log('hey there ... '); fun1(function () { console.log('hello from callback'); }); console.log('hello again ... '); /* hey there ... hello again ... hello from callback */ --- function fun2(callback) { var user = { id: 25, Name: 'Roby Cohen', Age:.

Read more

javascript apply and call

Posted by: RcBuilder  /   Category: Array / class / function / JAVASCRIPT / Object   /   No Comments
26
Jan
2016

javascript apply and call apply allows to call any function on any object, parameters as array, the caller object will serve as the context and we can reach it using the 'this' variable. syntax: .apply(, ); e.g: function Person(name) { this.name = name; } function doSomething(param1, param2) { // this refer to the caller object console.log(this.name + ' -> ' + param1 + ', ' + param2); } var person1.

Read more

javascript private/public

Posted by: RcBuilder  /   Category: class / function / JAVASCRIPT / Object / OOP / prototype   /   No Comments
26
Jan
2016

javascript private/public data members: private access defined using var within the object, can't be accessed from outside the object example: function Person(firstName, lastName) { var firstName = firstName; // data member var lastName = lastName; // data member ... ... } properties: public access defined using this, can be accessed from outside example: function Person(firstName, lastName) { this.firstName = firstName; // public property this.lastName = lastName; // public property ... ... } notice! we can define properties.

Read more

javascript that

Posted by: RcBuilder  /   Category: class / function / JAVASCRIPT / Object / OOP / prototype   /   No Comments
26
Jan
2016

javascript that use local variable within a custom object to save reference to the current object sometimes the 'this' variable not refer to the object contains the current function (callback calls, setTimeout etc.) the best way to handle this is by save an extra reference to the actual object (it's quite common to call it 'that') declare it in.

Read more

self-invoking functions

Posted by: RcBuilder  /   Category: class / function / JAVASCRIPT / Object / OOP   /   No Comments
26
Jan
2016

self-invoking functions declare & execute a function at the same time example: we created an anonymous function and invoked it within the declaration, the function creates a counter variable and return a reference to another function that increase this counter. the return function can access to the counter variable (as any function behaves - any function can access all of.

Read more

javascript closure

Posted by: RcBuilder  /   Category: class / function / JAVASCRIPT / Object / OOP   /   No Comments
26
Jan
2016

javascript closure the ability to create a private 'scope' for a function or an object! a closure is a persistent scope which holds on to local variables even after the code execution has moved out of that block tip: in javaScript, all functions have access to the scope "above" them. example: // note! plus = function(){ return ++counter; } var plus.

Read more

javascript arguments

Posted by: RcBuilder  /   Category: Array / class / function / JAVASCRIPT / Object   /   No Comments
26
Jan
2016

javascript arguments The arguments object is an Array-like object, it's a local variable available within all functions. the arguments object is only similar to an array but not a real one and it doesn't include any of the array functions except of length() we can pass any parameters we'd like and it automatically pass them as an arguments.

Read more
12
  • פיתוח מערכות
  • פתרונות טכנולוגים
  • קידום אתרים
  • בניית אתרים