echo "This is the initial content." > myfile.txt
add and commit file
git add myfile.txt
git commit -m "Initial commit"
make changes
echo "This is the modified content." > myfile.txt
git add myfile.txt
git commit -m "Modified myfile.txt"
revert last commit
git revert HEAD
or we can use specifying with the commit ID
git revert 4c04ecc
git log will return
Revert "added file 4" --- Commit name
This reverts commit 4c04eccff32e195ac0df17b1543f7f81de32d938. --- Commit id
JSONP
is a technique to get data from server without cross-domain issues.
JSONP does not use the XMLHttpRequest
, instead it uses <script>
tag.
window.onload = function() {
var s = document.createElement("script");
s.src = "https://www.w3schools.com/js/demo_jsonp.php";
document.write(s.outerHTML);
};
// This function will run after the content is fully loaded from the server
function myFunc(myObj) {
document.write(myObj.name + " is " + myObj.age + " and he lives in " + myObj.city);
}
Requesting a content from another domain can cause problems, due to cross-domain policy. <script>
tag does not have this problem and that is the reason why it uses the tag instead of using XMLHttpRequest
object.
...
Content of the remote demo_jsonp.php
filemyFunc({"name":"John", "age":30, "city":"New York"});
class myClass {
final function myFunction() {
echo "Parent";
}
}
// ERROR because a final method cannot be overridden in child classes.
class myClass2 extends myClass {
function myFunction() {
echo "Child";
}
}
The above code will generate the following error:Fatal error: Cannot override final method myClass::myFunction() in /home/user/scripts/code.php on line 9
class Say {
public function let() {
echo 'Let' . " ";
return $this;
}
public function me() {
echo 'Me' . " ";
return $this;
}
public function tell() {
echo 'Tell' . " ";
return $this;
}
public function you() {
echo 'You' . " ";
return $this;
}
public function something() {
echo 'Something' . " ";
}
}
$phrase = new Say;
$phrase->let()->me()->tell()->you()->something();
$this
inside static methodsclass Greeting {
public $nonStatic = 'some value';
public static function hello() {
return $this->nonStatic;
}
}
// echo Greeting::hello();
$obj1 = new Greeting();
echo $obj1->hello();
After executing the above code, following error will be generated:Fatal error: Uncaught Error: Using $this when not in object context
replaceChild
(newNode, oldNode) method is used.
JSwindow.onload = function() {
let p = document.createElement("p");
p.innerHTML = "This is new";
// Replaces the first p with the new one
let parent = document.getElementById("demo");
parent.replaceChild(p, document.getElementById("p1"));
};
HTML<div id="demo">
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>
Note: The code above creates a new paragraph element that replaces the existing p1
paragraphremoveChild
(node) method
JSwindow.onload = function() {
var parent = document.getElementById("demo");
parent.removeChild(document.getElementById("p1"));
};
HTML<div id="demo">
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>
insertBefore
(node1, node2) inserts node1
as a child before node2
JSfunction myFunction() {
// Creates new list item
let newItem = document.createElement("li");
newItem.innerHTML = "Water";
// Puts list item into myList before "tea" item
let list = document.getElementById("myList");
list.insertBefore(newItem, document.getElementById("tea"));
}
HTML<ul id="myList">
<li>Coffee</li>
<li id="tea">Tea</li>
<li>Cocacola</li>
</ul>
<p>Click the button to insert an item to the list.</p>
<button onclick="myFunction()">Try it</button>
class Foo {
public function __call($function, $arguments)
{
return "$function has been called with arguments: " . implode(', ', $arguments);
}
// public function fireFunction($one, $two, $three) {
// return "pre-defined method";
// }
}
$foo = new Foo();
echo $foo->fireFunction(5, 47, "third argument");
__call
is invoked when the method is inaccessible (when it's not public or does not exist at all)//calling the function in window.onload to make sure the HTML is loaded
window.onload = function() {
var x = document.getElementById("demo");
x.style.color = '#6600FF';
x.style.width = '100px';
};
HTML<div id="demo" style="width:400px">Some text inside this DIV</div>
Note: All CSS properties can be set and modified using JavaScript. We cannot use dashes (-) in the property names: these are replaced with camelCase
versions, where the compound words begin with a capital letter.
For example: the background-color
property should be referred to as backgroundColor
.