Created
July 3, 2013 13:52
-
-
Save shinofara/5918011 to your computer and use it in GitHub Desktop.
【javascriptを使う人に知って貰いたい(エンジニア、デザイナ問わず)】Typescriptを使ってjavascriptをコンパイルを作成する。 ref: http://qiita.com/shinofara@github/items/4396b713ead5a4ae53b4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ npm install -g typescript |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ vim sample.ts | |
class shop { | |
price: number; | |
num: number; | |
constructor() { | |
this.num = 10; | |
} | |
setPrice(price: number) { | |
this.price = price; | |
} | |
calculatePrice() { | |
var total: number = this.num * this.price; | |
return this.price + '円のりんごを' + this.num + '個購入した場合' + total + '円です。'; | |
} | |
} | |
var sp = new shop(); | |
sp.setPrice(1000); | |
document.body.innerHTML = sp.calculatePrice(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ tsc sample.ts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ls sample.* | |
sample.js sample.ts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ vim sample.js | |
var shop = (function () { | |
function shop() { | |
this.num = 10; | |
} | |
shop.prototype.setPrice = function (price) { | |
this.price = price; | |
}; | |
shop.prototype.calculatePrice = function () { | |
var total = this.num * this.price; | |
return this.price + '円のりんごを' + this.num + '個購入した場合' + total + '円です。'; | |
}; | |
return shop; | |
})(); | |
var sp = new shop(); | |
sp.setPrice(1000); | |
document.body.innerHTML = sp.calculatePrice(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ vim sample.ts | |
class shop { | |
price: number; | |
num: number; | |
constructor() { | |
this.num = 10; | |
} | |
setPrice(price: number) { | |
this.price = price; | |
} | |
calculatePrice() { | |
var total: number = this.num * this.price; | |
return this.price + '円のりんごを' + this.num + '個購入した場合' + total + '円です。'; | |
} | |
} | |
var sp = new shop(); | |
sp.setPrice('1000'); | |
document.body.innerHTML = sp.calculatePrice(); | |
$ tsc sample.ts | |
sample.ts(20,4): error TS2081: Supplied parameters do not match any signature of call target. | |
sample.ts(20,4): error TS2087: Could not select overload for 'call' expression. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment