2015年11月11日水曜日
Backbone.JSからAngular2まで、全9大JavaScriptフレームワークを書き比べた!
15:21
No comments
First Name: <input id="firstName"/><br> Last Name: <input id="lastName"/><br> Full Name: <span id="fullName"></span><br>
function updateFullName(){ var fullName = $("#firstName").val() + " " + $("#lastName").val(); $("#fullName").text(fullName); } $("#firstName, #lastName").bind("change keyup", function(){ updateFullName(); }); $("#firstName").val("Taro"); $("#lastName").val("Yamada"); updateFullName();
<div id="person"> First Name: <input id="firstName" value=""><br> Last Name: <input id="lastName" value=""><br> Full Name: <span id="fullName"></span> </div>
Person = Backbone.Model.extend({}); PersonView = Backbone.View.extend({ el: '#person', events: { 'change': 'change', }, initialize: function(){ this.listenTo(this.model, 'change', this.render); this.render(); }, change: function(){ var firstName = $('#firstName').val(); var lastName = $('#lastName').val(); this.model.set({firstName: firstName, lastName: lastName}); }, render: function(){ this.$('#firstName').val(this.model.get('firstName')); this.$('#lastName').val(this.model.get('lastName')); var fullName = this.model.get('firstName') + ' ' + this.model.get('lastName'); this.$('#fullName').text(fullName); }, }); person = new Person({lastName: "Yamada", firstName: "Taro"}); personView = new PersonView({model: person});
<script type="text/x-handlebars" data-template-name="index"> First Name:{{input type="text" value=firstName}}<br/> Last Name:{{input type="text" value=lastName}}<br/> Full Name: {{model.fullName}}<br/> </script>
App = Ember.Application.create(); App.Person = Ember.Object.extend({ firstName: null, lastName: null, fullName: function() { return this.get('firstName') + ' ' + this.get('lastName'); }.property('firstName', 'lastName') }); var person = App.Person.create({ firstName: "Taro", lastName: "Yamada" }); App.Router.map(function () { }); App.IndexRoute = Ember.Route.extend({ model:function () { return person; } });
<p>First name:<input data-bind="value: firstName" /></p> <p>Last name:<input data-bind="value: lastName" /></p> <p>Full name:<span data-bind="text: fullName"></span></p>
function AppViewModel() { this.firstName = ko.observable("Taro"); this.lastName = ko.observable("Yamada"); this.fullName = ko.computed(function() { return this.firstName() + " " + this.lastName(); }, this); } // Activates knockout.js ko.applyBindings(new AppViewModel());
<div ng-app ng-controller="PersonController"> First Name: <input type=text ng-model="firstName"> <br> Last Name: <input type=text ng-model="lastName"><br> Full Name: {{getFullName()}} </div>
function PersonController($scope) { $scope.firstName = "Taro"; $scope.lastName = "Yamada"; $scope.getFullName = function() { return $scope.firstName + " " + $scope.lastName; }; }
var MyApp = React.createClass({ getInitialState: function(){ return { firstName: this.props.firstName, lastName: this.props.lastName, } }, handleChange: function(){ var firstName = this.refs.firstName.getDOMNode().value; var lastName = this.refs.lastName.getDOMNode().value; this.setState({ firstName: firstName, lastName: lastName, }); }, render: function() { var fullName = this.state.firstName + this.state.lastName; return ( <div> First name: <input ref="firstName" onChange={this.handleChange} value={this.state.firstName}/><br/> Last name: <input ref="lastName" onChange={this.handleChange} value={this.state.lastName}/><br/> Full name: {fullName} </div>); } }); React.render(<MyApp firstName="Taro" lastName="Yamada" />, document.body);
<script type="text/reactive" id="tpl"> First Name:<input type="text" value="{{firstName}}"/><br/> Last Name:<input type="text" value="{{lastName}}"/><br/> Full Name: {{fullName()}}<br/> </script> <div id='container'></div>
var ractive = new Ractive({ el: 'container', template: '#tpl', data: { firstName: 'Taro', lastName: 'Yamada', fullName: function () { return this.get( 'firstName' ) + ' ' + this.get( 'lastName' ); } }, });
<div id="person"> First Name: <input v-model="firstName"><br/> Last Name: <input v-model="lastName"><br/> Full Name: {{fullName}}<br/> </div>
var demo = new Vue({ el: '#person', data: { firstName: 'Taro', lastName: 'Yamada', }, computed: { fullName: { get: function(){ return this.firstName + ' ' + this.lastName; } } }, })
<template> <section> <form role="form"> First Name: <input type="text" value.bind="firstName"><br/> Last Name: <input type="text" value.bind="lastName"><br/> Full name: ${fullName} </form> </section> </template>
export class Welcome{ constructor(){ this.firstName = 'Taro'; this.lastName = 'Yamada'; } get fullName(){ return `${this.firstName} ${this.lastName}`; } }
First Name: <input type=text [value]="firstName" #first (keyup)="firstNameChanged($event, first)"><br/> Last Name: <input type=text [value]="lastName" #last (keyup)="lastNameChanged($event, last)"><br/> Full Name: {{fullName}}
import {Component, Template, bootstrap} from 'angular2/angular2'; // Annotation section @Component({ selector: 'my-app' }) @Template({ url: 'app.html' }) // Component controller class MyAppComponent { constructor() { this.firstName = 'Taro'; this.lastName = 'Yamada'; this.updateFullname(); } changed($event, el){ console.log("changes", this.name, el.value); this.name = el.value; } updateFullname(){ this.fullName = this.firstName + " " + this.lastName; } firstNameChanged($event, first){ this.firstName = first.value; this.updateFullname(); } lastNameChanged($event, last){ this.lastName = last.value; this.updateFullname(); } } bootstrap(MyAppComponent);
0 コメント:
コメントを投稿