Object-like Class, no instantiation is needed.
var name = {
methodOne: function() {
// code
},
methodTwo: function( param ) {
// code
}
};
name.methodTwo('hello');
Function-like Class using prototype, it must be instantiated before usage.
!! pattern NO GOOD !!
private properties are the same for all instances, more like STATIC properties!
// namespace 'Office'
var Office = Office || {};
Office.Users = (function() {
// constructor
function user() {
console.log(isAdmin('pesho'));
}
// private properties, more like STATIC properties!
user.username = 'unknown';
user.age = 'unknown';
// public properties
user.prototype.state = 'development';
user.prototype.deploy = false;
// private method
function isAdmin(name) {
return name == 'admin' ? true : false;
}
// public methods
user.prototype.setUsername = function(username) {
user.username = username;
};
user.prototype.getUsername = function() {
return user.username;
};
user.prototype.setAge = function(age) {
user.age = age;
};
user.prototype.getAge = function() {
return user.age;
};
return user;
}());
var test = new Office.Users();
Function-like Class, it must be instantiated before usage.
function cityLocation() {
var city = "Paris";
return {
get: function() {
console.log(city);
},
set: function(newCity) {
city = newCity;
}
};
}
var myLocation = cityLocation();
myLocation.get(); // output: Paris
myLocation.set('Sydney');
myLocation.get(); // output: Sydney
JavaScript is a very flexible object-oriented language when it comes to syntax. It’s important to note that there are no classes in JavaScript. Functions can be used to somewhat simulate classes, but in general JavaScript is a class-less language.
Ever wondered if you could install the LAMP stack (on Linux Mint/Ubuntu) with one simple command? One would say let's do:
$ sudo apt-get install php5 mysql-server apache2
However, there's a shorter way of accomplishing that. Try:
$ sudo apt-get install lamp-server^
Or if you like things a bit more graphical, you could do:
$ sudo tasksel install lamp-server
And your LAMP is ready!
jQuery is just wrapping the standard resize DOM event, eg.
window.onresize = function(event) {
// code..
};
jQuery may do some work to ensure that the resize event gets fired consistently in all browsers, but I'm not sure if any of the browsers differ, but I'd encourage you to test in Firefox, Safari, and IE.
window.onload = function()
{
window.WIDTH = document.getElementById('id').offsetWidth;
window.HEIGHT = document.getElementById('id').offsetHeight;
}
! Adding window to the variable makes it global.
You should use the .offsetWidth and .offsetHeight properties. Note they belong to the element!
Beware! offsetHeight/offsetWidth can return 0 if you've done certain DOM modifications to the element recently. You may have to call this code in a setTimeout call after you've modified the element.
Learn about the PHP socket programming functions and how to create a daemon/service. There are two videos explaining the code that you can find here: link
Socket Programming: Video 1 Video 2
We all know HTTP is connection-less protocol, but socket programming allows you to stay connected to your users’ browser and update any information you want on the page.
Create the connection:
$socket = socket_create(AF_INET,SOCK_STREAM,0)
Binding to a specific port:
PHP
$ip = "127.0.0.1";
$port = 123;
socket_bind($socket,$ip,$port)
Listening to your customers:
socket_listen($socket)
Accept any requests:
$client = socket_accept($socket)
Server sends message to user:
// welcome the user
$message = "\n Hey! Welcome to another exciting talk! \n\n";
socket_write($client, $message, strlen($message));
Server receives message from user:
$clientMssg = socket_read($client,2048,PHP_NORMAL_READ)