First do a

history -c

and then a

history -w

to actually write everything on the .bash_history file (and overwrite it).
Then a

reset

clears the scroll buffer as well and all the past is forgotten and erased!


source - https://lists.fedoraproject.org/pipermail/users/2006-May/290451.html






# history -c && history -w


Posted by linuxism
,


JavaScript Function Invocation


JavaScript functions can be invoked in 4 different ways.

Each method differs in how this is initialized.


The this Keyword

In JavaScript, the thing called this, is the object that "owns" the current code.

The value of this, when used in a function, is the object that "owns" the function.

NoteNote that this is not a variable. It is a keyword. You cannot change the value of this.


Invoking a JavaScript Function

You have already learned that the code inside a JavaScript function will execute when "something" invokes it.

The code in a function is not executed when the function is defined. It is executed when the function is invoked.

Some people use the term "call a function" instead of "invoke a function".

It is also quite common to say "call upon a function", "start a function", or "execute a function".

In this tutorial, we will use invoke, because a JavaScript function can be invoked without being called.


Invoking a Function as a Function

Example

function myFunction(a, b) {
    return a * b;
}
myFunction(102);           // myFunction(10, 2) will return 20

Try it Yourself »

The function above does not belong to any object. But in JavaScript there is always a default global object.

In HTML the default global object is the HTML page itself, so the function above "belongs" to the HTML page.

In a browser the page object is the browser window. The function above automatically becomes a window function.

myFunction() and window.myFunction() is the same function:

Example

function myFunction(a, b) {
    return a * b;
}
window.myFunction(102);    // window.myFunction(10, 2) will also return 20

Try it Yourself »

NoteThis is a common way to invoke a JavaScript function, but not a good practice in computer programming.
Global variables, methods, or functions can easily create name conflicts and bugs in the global object.


The Global Object

When a function is called without an owner object, the value of this becomes the global object.

In a web browser the global object is the browser window.

This example returns the window object as the value of this:

Example

function myFunction() {
    return this;
}
myFunction();                // Will return the window object

Try it Yourself »

NoteInvoking a function as a global function, causes the value of this to be the global object.
Using the window object as a variable can easily crash your program.


Invoking a Function as a Method

In JavaScript you can define function as object methods.

The following example creates an object (myObject), with two properties (firstName and lastName), and a method (fullName):

Example

var myObject = {
    firstName:"John",
    lastName: "Doe",
    fullName: function () {
        return this.firstName + " " + this.lastName;
    }
}
myObject.fullName();         // Will return "John Doe"

Try it Yourself »

The fullName method is a function. The function belongs to the object. myObject is the owner of the function.

The thing called this, is the object that "owns" the JavaScript code. In this case the value of this is myObject.

Test it! Change the fullName method to return the value of this:

Example

var myObject = {
    firstName:"John",
    lastName: "Doe",
    fullName: function () {
        return this;
    }
}
myObject.fullName();          // Will return [object Object] (the owner object)

Try it Yourself »

NoteInvoking a function as an object method, causes the value of this to be the object itself.


Invoking a Function with a Function Constructor

If a function invocation is preceded with the new keyword, it is a constructor invocation.

It looks like you create a new function, but since JavaScript functions are objects you actually create a new object:

Example

// This is a function constructor:
function myFunction(arg1, arg2) {
    this.firstName = arg1;
    this.lastName  = arg2;
}

// This creates a new object
var x = new myFunction("John","Doe");
x.firstName;                             // Will return "John"

Try it Yourself »

A constructor invocation creates a new object. The new object inherits the properties and methods from its constructor.

NoteThe this keyword in the constructor does not have a value.
The value of this will be the new object created when the function is invoked.


Invoking a Function with a Function Method

In JavaScript, functions are objects. JavaScript functions have properties and methods.

call() and apply() are predefined JavaScript function methods. Both methods can be used to invoke a function, and both methods must have the owner object as first parameter.

Example

function myFunction(a, b) {
    return a * b;
}
myObject = myFunction.call(myObject, 102);     // Will return 20

Try it Yourself »


Example

function myFunction(a, b) {
    return a * b;
}
myArray = [102];
myFunction.apply(myObject, myArray);             // Will also return 20

Try it Yourself »

Both methods takes an owner object as the first argument. The only difference is that call() takes the function arguments separately, and apply() takes the function arguments in an array.

In JavaScript strict mode, the first argument becomes the value of this in the invoked function, even if the argument is not an object.

In "non-strict" mode, if the value of the first argument is null or undefined, it is replaced with the global object.

NoteWith call() or apply() you can set the value of this, and invoke a function as a new method of an existing object.



source - http://www.w3schools.com/js/js_function_invocation.asp


'Development > JavaScript' 카테고리의 다른 글

javaScript - Performance  (0) 2015.07.06
javaScript - hoisting  (0) 2015.07.06
Model–view–presenter, Backbone.js  (0) 2015.07.01
javascript - KeyboardEvent keyCode Property  (0) 2015.06.26
javascript - use strict  (0) 2014.08.06
Posted by linuxism
,


Model–view–presenter

From Wikipedia, the free encyclopedia


Diagram that depicts the Model View Presenter (MVP) GUI design pattern.


Model–view–presenter (MVP) is a derivation of the model–view–controller (MVC) architectural pattern, and is used mostly for building user interfaces.

In MVP the presenter assumes the functionality of the "middle-man". In MVP, all presentation logic is pushed to the presenter.[1]

Pattern description[edit]

MVP is a user interface architectural pattern engineered to facilitate automated unit testing and improve the separation of concerns in presentation logic:

  • The model is an interface defining the data to be displayed or otherwise acted upon in the user interface.
  • The view is a passive interface that displays data (the model) and routes user commands (events) to the presenter to act upon that data.
  • The presenter acts upon the model and the view. It retrieves data from repositories (the model), and formats it for display in the view.

Normally, the view implementation instantiates the concrete presenter object, providing a reference to itself. The following C# code demonstrates a simple view constructor, where ConcreteDomainPresenterimplements the IDomainPresenter interface:

public class DomainView : IDomainView
{
    private IDomainPresenter domainPresenter = null;

    ///<summary>Constructor</summary>
    public DomainView()
    {
        domainPresenter = new ConcreteDomainPresenter(this);
    }
}

The degree of logic permitted in the view varies among different implementations. At one extreme, the view is entirely passive, forwarding all interaction operations to the presenter. In this formulation, when a user triggers an event method of the view, it does nothing but invoke a method of the presenter that has no parameters and no return value. The presenter then retrieves data from the view through methods defined by the view interface. Finally, the presenter operates on the model and updates the view with the results of the operation. Other versions of model-view-presenter allow some latitude with respect to which class handles a particular interaction, event, or command. This is often more suitable for web-based architectures, where the view, which executes on a client's browser, may be the best place to handle a particular interaction or command.

From a layering point of view, the presenter class might be considered as belonging to the application layer in a multilayered architecture system, but it can also be seen as a presenter layer of its own between the application layer and the user interface layer.

Implementation in .NET[edit]

The .NET environment supports the MVP pattern much like any other development environment. The same model and presenter class can be used to support multiple interfaces, such as an ASP.NET Web application, a Windows Forms application, or a Silverlight application. The presenter gets and sets information from/to the view through an interface that can be accessed by the interface (view) component.

In addition to manually implementing the pattern, a model-view-presenter framework may be used to support the MVP pattern in a more automated fashion. Below is a list of such frameworks under the .NET platform.

.NET frameworks[edit]

Implementation in Java[edit]

In a Java (AWT/Swing/SWT) application, the MVP pattern can be used by letting the user interface class implement a view interface.

The same approach can be used for Java web-based applications, since modern Java component-based Web frameworks allow development of client-side logic using the same component approach as thick clients.

Implementing MVP in Google Web Toolkit requires only that some component implement the view interface. The same approach is possible using the Echo2 Web framework.

MVP can be implemented in Java SE (AWT and Swing) applications using the Biscotti and MVP4J frameworks.

Java frameworks[edit]

Implementation in PHP[edit]

As of PHP's flexible runtime environment, there are wide possibilities of approaches of an application logic. A great example of MVP pattern implementation is Nette Framework implementing rich presenter layer and view layer through templating system Latte (web template engine). Implementation of model layer is left on the end application programmer.

PHP frameworks[edit]

History[edit]

The model-view-presenter software pattern originated in the early 1990s at Taligent, a joint venture of AppleHP, and IBM, and was the underlying programming model for application development in Taligent'sC++-based CommonPoint environment. The pattern was later migrated by Taligent to Java and popularized in a paper by Taligent CTO Mike Potel.[3] After Taligent's demise in 1997, Andy Bower and Blair McGlashan of Dolphin Smalltalk adapted the MVP pattern to form the basis for their Smalltalk user interface framework.[4] In 2006, Microsoft began incorporating MVP into their documentation and examples for user interface programming in the .NET framework.[5][6] The evolution and multiple variants of the MVP pattern, including the relationship of MVP to other design patterns such as MVC, is discussed in detail in an article by Martin Fowler[7] and another by Derek Greer[8]

See also[edit]

References[edit]

External links[edit]



source - https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93presenter








Backbone.js

From Wikipedia, the free encyclopedia


Backbone.js
BackboneJS logo.png
Developer(s)Jeremy Ashkenas
Initial releaseOctober 13, 2010; 4 years ago
Stable release1.2.0 / May 13, 2015[1]
Development statusActive
Written inJavaScript
Operating systemCross-platform
Size7.3 KB production
69 KB development
TypeJavaScript library
LicenseMIT
Websitebackbonejs.org


Backbone.js is a JavaScript library with a RESTful JSON interface and is based on the model–view–presenter (MVP) application design paradigm. Backbone is known for being lightweight, as its only dependency is on one JavaScript library,[2] Underscore.js. It is designed for developing single-page web applications,[3] and for keeping various parts of web applications (e.g. multiple clients and the server) synchronized.[4] Backbone was created by Jeremy Ashkenas, who is also known forCoffeeScript.[5]

Use[edit]

The following web applications are built with Backbone.js[6]:

References[edit]

Further reading[edit]

External links[edit]



source - https://en.wikipedia.org/wiki/Backbone.js



'Development > JavaScript' 카테고리의 다른 글

javaScript - hoisting  (0) 2015.07.06
javascript - Function Invocation  (0) 2015.07.01
javascript - KeyboardEvent keyCode Property  (0) 2015.06.26
javascript - use strict  (0) 2014.08.06
javascript - Naming Conventions  (0) 2014.07.18
Posted by linuxism
,