Results: 1578
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
Select table comment
Selects comment of
channels
table which exists in the
geiger
database
SELECT table_comment 
FROM INFORMATION_SCHEMA.TABLES 
WHERE table_schema='geiger' 
    AND table_name='channels'
by Valeri Tandilashvili
4 years ago
0
MySQL
Table comment
1
Set table comment
Sets comment for the specified table to make it easy for other developers what the purpose of this table is
ALTER TABLE `the_table_name` comment 'Some text about the table'
by Valeri Tandilashvili
4 years ago
0
MySQL
1
A static property (trvar) can only be accessed using the classname (C1). But a static function (stfunc) can be accessed using the classname or the instance ($obj).
trait Counter {
    static $trvar=1;

    public static function stfunc() {
        echo "Hello world!"
    }
}
class C1 {
    use Counter;
}
print "\nTRVAR: " . C1::$trvar . "\n";   //prints 1

$obj = new C1();
C1::stfunc();   //prints  Hello world!
$obj->stfunc();   //prints Hello world!
by გიორგი უზნაძე
4 years ago
0
PHP
OOP
Traits
0

trait A
{
    private function smallTalk()
    {
        echo 'a';
    }

    private function bigTalk()
    {
        echo 'A';
    }
}

trait B
{
    private function smallTalk()
    {
        echo 'b';
    }

    private function bigTalk()
    {
        echo 'B';
    }
}

trait C
{
    public function smallTalk()
    {
        echo 'c';
    }

    public function bigTalk()
    {
        echo 'C';
    }
}

class Talker
{
    use A, B, C {
        //visibility for methods that will be involved in conflict resolution
        B::smallTalk as public;
        A::bigTalk as public;

        //conflict resolution
        B::smallTalk insteadof A, C;
        A::bigTalk insteadof B, C;

        //aliases with visibility change
        B::bigTalk as public Btalk;
        A::smallTalk as public asmalltalk;
       
        //aliases only, methods already defined as public
        C::bigTalk as Ctalk;
        C::smallTalk as cmallstalk;
    }

}

(new Talker)->bigTalk();//A
(new Talker)->Btalk();//B
(new Talker)->Ctalk();//C

(new Talker)->asmalltalk();//a
(new Talker)->smallTalk();//b
(new Talker)->cmallstalk();//c
by გიორგი უზნაძე
4 years ago
0
PHP
OOP
Traits
0
Arrow function inside "map" function CODE
Regular anonymous function:
let numbers = [10, 100, 1000]

let doubled = numbers.map(function(x){
  return x * 2
})

document.write(doubled)
Alternative arrow function:
let doubled = numbers.map((x) => { return x * 2 })
If it's only a single line we don't need curly brackets and the keyword
return
let doubled = numbers.map((x) => x * 2);
If the arrow function has only one parameter, it does not need parentheses:
let doubled = numbers.map(x => x * 2);
Note: We only need
parentheses
if we had zero or more than one parameters
by Valeri Tandilashvili
4 years ago
0
JavaScript
Arrow functions
Functions
2
Arrow function CODE
Regular anonymous function:
// Anonymous function
document.addEventListener('click', function(){
  console.log('You clicked me!');
})
The same function with arrow function syntax
// Arrow function
document.addEventListener('click', () => {
  console.log('You clicked me!');
})
Even more minimalistic arrow function
// More minimalistic arrow function 
document.addEventListener('click', () => console.log('You clicked me!'))
by Valeri Tandilashvili
4 years ago
0
JavaScript
Arrow functions
1
function "call" CODE
If we call
driveCar()
function using
call()
function,
this
will refer to the object that will be passed. In this case:
john
object
let john = {
  firstName: 'John',
  lastName: 'Doe'
}

function driveCar() {
  document.write(this.firstName + ' ' + this.lastName + ' is driving a car<br/>')
}

driveCar.call(john)
by Valeri Tandilashvili
4 years ago
0
JavaScript
Function functions
1
Variables added to the global WINDOW object CODE
Variable
lastName
declared by the keyword
let
is not added to the global
window
object. That is why the variable is equal to
undefined
// Declaring variable using keyword "var"
var firstName = "Jet"

// Declaring variable using keyword "let"
let lastName = "Li"

// Declaring variable without using any keyword
carMark = "Tesla"

function driveCar() {
  console.log(this.firstName + ' ' + this.lastName + ' is driving a car '+this.carMark)
}

driveCar()
The result will be:
Jet undefined is driving a car Tesla
Because declaring variable with
var
keyword and without any declaration keyword are the same. Both add the variable to the global
window
object. After running the above code, global object
window
will have
firstName
and
lastName
attributes
window.firstName;  // "Jet"
window.lastName;  // undefined
window.carMark;  // "Tesla"
by Valeri Tandilashvili
4 years ago
0
JavaScript
THIS
2
Default THIS context inside function CODE
this
inside
driveCar()
function refers to the global window object. Global variables
firstName
and
lastName
are added to the
window
object. That is why they are visible using the keyword
firstName = "Jack"
lastName = "Ma"

function driveCar() {
  document.write(this.firstName + ' ' + this.lastName + ' is driving a car<br/>')
}

driveCar()
If we call the same function using
call
function,
this
will refer to the object that will be passed. In this case:
john
object
let john = {
  firstName: 'John',
  lastName: 'Doe'
}

function driveCar() {
  document.write(this.firstName + ' ' + this.lastName + ' is driving a car<br/>')
}

driveCar.call(john)
by Valeri Tandilashvili
4 years ago
0
JavaScript
THIS
1
this
inside
fn()
function refers to the global
window
object. That is why
firstName
and
lastName
attributes are not accessible using
this
keyword
let john = {
  firstName: 'John',
  lastName: 'Doe',
  driveCar() {
    function fn () {
      console.log(this.firstName + ' ' + this.lastName + ' is driving a car');  // "undefined undefined is driving a car"
      console.log(this);
    }
    fn(); // fn.call(this);
    console.log(this.firstName + ' ' + this.lastName + ' is driving a car'); 
    console.log(this)
  }
}

john.driveCar(); 
In order to fix the issue, one of the ways is to use
call
function and pass the object that we want
this
to refer to inside the
fn()
function
fn.call(this);
Inside
driveCar()
function
this
refers to the
john
object because it is called through
john
object
john.driveCar();
by Valeri Tandilashvili
4 years ago
0
JavaScript
THIS
The 10 Days of JavaScript
1
Results: 1578