Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
能源人都在看,點(diǎn)擊右上角加'關(guān)注'】
為慶祝中華人民共和國(guó)成立70周年,公司策劃拍攝了《祖國(guó),我想對(duì)你說(shuō)》視頻短片。
該片參演人數(shù)眾多、現(xiàn)場(chǎng)氛圍熱烈、愛(ài)國(guó)情感濃厚。公司各單位廣大干部職工紛紛用最誠(chéng)摯的心聲表達(dá)對(duì)祖國(guó)的熱愛(ài)和祝福,寄托對(duì)美好新時(shí)代的期盼和向往。
9月30日,該片登上“學(xué)習(xí)強(qiáng)國(guó)”平臺(tái),在全國(guó)范圍內(nèi)充分展現(xiàn)了良好的企業(yè)形象,收到了良好的社會(huì)評(píng)價(jià),更提振了廣大干部職工“重鑄永煤新輝煌”的士氣信心。
讓我們唱響新時(shí)代的主旋律,共同祝愿重鑄永煤新輝煌的目標(biāo)早日實(shí)現(xiàn),祝愿?jìng)ゴ笞鎳?guó)繁榮富強(qiáng),祝愿全國(guó)人民幸福安康!
學(xué)習(xí)強(qiáng)國(guó)鏈接:https://article.xuexi.cn/articles/index.html?art_id=8209736260941147772&study_style_id=video_default&source=share&share_to=wx_single&from=timeline&isappinstalled=0
責(zé) 編:商猛猛 編 輯:陶 夢(mèng)
覺(jué)得不錯(cuò),請(qǐng)點(diǎn)這里↓↓↓
免責(zé)聲明:以上內(nèi)容轉(zhuǎn)載自永煤集團(tuán),所發(fā)內(nèi)容不代表本平臺(tái)立場(chǎng)。
全國(guó)能源信息平臺(tái)聯(lián)系電話:010-65367827,郵箱:hz@people-energy.com.cn,地址:北京市朝陽(yáng)區(qū)金臺(tái)西路2號(hào)人民日?qǐng)?bào)社
顏色屬性被用來(lái)設(shè)置文字的顏色。
顏色是通過(guò)CSS最經(jīng)常的指定:
一個(gè)網(wǎng)頁(yè)的文本顏色是指在主體內(nèi)的選擇:
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=640, user-scalable=no">
<title>項(xiàng)目</title>
<style>
body {
color: blue;
}
h1 {
color: #00ff00;
}
h2 {
color: rgb(255, 0, 0);
}
</style>
</head>
<body>
<h2>hello world</h2>
<h1>welcome to CaoZhou</h1>
</body>
</html>
注:對(duì)于W3C標(biāo)準(zhǔn)的CSS:如果你定義了顏色屬性,你還必須定義背景色屬性。
文本排列屬性是用來(lái)設(shè)置文本的水平對(duì)齊方式。
文本可居中或?qū)R到左或右,兩端對(duì)齊。
當(dāng)text-align設(shè)置為"justify",每一行被展開(kāi)為寬度相等,左,右外邊距是對(duì)齊(如雜志和報(bào)紙)。
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
h1 {
text-align: center;
}
p.date {
text-align: right;
}
p.main {
text-align: justify;
}
</style>
</head>
<body>
<p class="date">2015 年 3 月 14 號(hào)</p>
<p class="main"> 從前有個(gè)書(shū)生,和未婚妻約好在某年某月某日結(jié)婚。到那一天,未婚妻卻嫁給了別人。書(shū)生受此打擊, 一病不起。 這時(shí),路過(guò)一游方僧人,從懷里摸出一面鏡子叫書(shū)生看。書(shū)生看到茫茫大海,一名遇害的女子一絲不掛地躺在海灘上。路過(guò)一人, 看一眼,搖搖頭,走了。又路過(guò)一人,將衣服脫下,給女尸蓋上,走了。再路過(guò)一人,過(guò)去,挖個(gè)坑,小心翼翼把尸體掩埋了。 僧人解釋道, 那具海灘上的女尸,就是你未婚妻的前世。你是第二個(gè)路過(guò)的人,曾給過(guò)他一件衣服。她今生和你相戀,只為還你一個(gè)情。但是她最終要報(bào)答一生一世的人,是最后那個(gè)把她掩埋的人,那人就是他現(xiàn)在的丈夫。書(shū)生大悟,病愈。
</p>
<p><b>注意:</b> 重置瀏覽器窗口大小查看 "justify" 是如何工作的。</p>
</body>
</html>
text-decoration 屬性用來(lái)設(shè)置或刪除文本的裝飾。
從設(shè)計(jì)的角度看 text-decoration屬性主要是用來(lái)刪除鏈接的下劃線:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.none {}
.del {
text-decoration: none;
}
</style>
</head>
<body>
<p>原來(lái)的樣子</p>
<a href="#" class="none">wwwwwwwwwwwwwwwwww</a>
<p>去掉下劃線</p>
<a href="#" class="del">wwwwwwwwwwwwwwwwwwwww</a>
</body>
</html>
也可以這樣裝飾文字:
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=640, user-scalable=no">
<title>項(xiàng)目</title>
<style>
h1 {
text-decoration: overline;
}
h2 {
text-decoration: line-through;
}
h3 {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
</body>
</html>
注:不建議強(qiáng)調(diào)指出不是鏈接的文本,因?yàn)檫@常常混淆用戶。
text-transform文本轉(zhuǎn)換屬性是用來(lái)指定在一個(gè)文本中的大寫和小寫字母。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=640, user-scalable=no">
<title>項(xiàng)目</title>
<style>
p.uppercase {
text-transform: uppercase;
}
p.lowercase {
text-transform: lowercase;
}
p.capitalize {
text-transform: capitalize;
}
</style>
</head>
<body>
<p class="uppercase">This is some text.</p>
<p class="lowercase">This is some text.</p>
<p class="capitalize">This is some text.</p>
</body>
</html>
text-indent文本縮進(jìn)屬性是用來(lái)指定文本的第一行的縮進(jìn)。
p {text-indent:50px;}
增加或減少字符之間的空間。
<style>
h1 {
letter-spacing:2px;
}
h2 {
letter-spacing:-3px;
}
</style>
指定在一個(gè)段落中行之間的空間。
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=640, user-scalable=no">
<title>項(xiàng)目</title>
<style>
p.small {
line-height: 70%;
}
p.big {
line-height: 200%;
}
</style>
</head>
<body>
<p>
This is a paragraph with a standard line-height.<br> This is a paragraph with a standard line-height.<br> The default line height in most browsers is about 110% to 120%.<br>
</p>
<p class="small">
This is a paragraph with a smaller line-height.<br> This is a paragraph with a smaller line-height.<br> This is a paragraph with a smaller line-height.<br> This is a paragraph with a smaller line-height.<br>
</p>
<p class="big">
This is a paragraph with a bigger line-height.<br> This is a paragraph with a bigger line-height.<br> This is a paragraph with a bigger line-height.<br> This is a paragraph with a bigger line-height.<br>
</p>
</body>
</html>
增加一個(gè)段落中的單詞之間的空白空間。
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=640, user-scalable=no">
<title>項(xiàng)目</title>
<style type="text/css">
p {
word-spacing: 30px;
}
</style>
</head>
<body>
<p>
This is some text. This is some text.
</p>
</body>
</html>
設(shè)置文本的垂直對(duì)齊圖像。
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=640, user-scalable=no">
<title>項(xiàng)目</title>
<style>
img{
width: 200px;
height: 100px;
}
img.top {
vertical-align: text-top;
}
img.bottom {
vertical-align: text-bottom;
}
</style>
</head>
<body>
<p>An <img src="img/logo.png" /> image with a default alignment.</p>
<p>An <img class="top" src="img/logo.png" /> image with a text-top alignment.</p>
<p>An <img class="bottom" src="img/logo.png" /> image with a text-bottom alignment.</p>
</body>
</html>
設(shè)置文本陰影。
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=640, user-scalable=no">
<title>項(xiàng)目</title>
<style>
h1{
text-shadow: 2px 2px #FF0000;
}
</style>
</head>
<body>
<h1>Text-shadow effect</h1>
</body>
</html>
本文主要介紹了CSS文本樣式實(shí)際應(yīng)用中應(yīng)該如何去操作,通過(guò)講解文本中對(duì)應(yīng)的屬性去改變文本的表現(xiàn)形式。使用豐富的效果圖的展示,能夠更直觀的看到運(yùn)行的效果,能夠更好的理解。使用Html語(yǔ)言,代碼結(jié)構(gòu)更佳的清晰,能夠幫助你更好的學(xué)習(xí)。
文地址:Understanding Design Patterns in JavaScript
原文作者:Sukhjinder Arora
譯者:HelloGitHub-Robert
當(dāng)啟動(dòng)一個(gè)新的項(xiàng)目時(shí)候,我們不應(yīng)該馬上開(kāi)始編程。而是首先應(yīng)該定義項(xiàng)目的目的和范圍,然后列出其功能或規(guī)格。如果你已經(jīng)開(kāi)始編程或者正在從事一個(gè)復(fù)雜的項(xiàng)目,則應(yīng)該選擇一個(gè)最適合你項(xiàng)目的設(shè)計(jì)模式。
在軟件工程中,設(shè)計(jì)模式是針對(duì)軟件設(shè)計(jì)中常見(jiàn)問(wèn)題的可重用解決方案。設(shè)計(jì)模式也是經(jīng)驗(yàn)豐富的開(kāi)發(fā)人員針對(duì)特定問(wèn)題的最佳實(shí)踐。它可以被當(dāng)作編程的模板。
許多工程師要么認(rèn)為設(shè)計(jì)模式浪費(fèi)時(shí)間,要么不知道如何恰當(dāng)?shù)氖褂迷O(shè)計(jì)模式。但如果能正確使用設(shè)計(jì)模式,則可以幫助你寫出更好的可讀性更高的代碼,并且代碼更容易被維護(hù)和理解。
最重要的是,設(shè)計(jì)模式為軟件開(kāi)發(fā)人員提供了通用的詞匯表。它們能讓學(xué)習(xí)你代碼的人很快了解代碼的意圖。例如,如果你的項(xiàng)目中使用了裝飾器模式,那么新的開(kāi)發(fā)可以很快就知道這段代碼的作用,從而他們可以將更多精力放在解決業(yè)務(wù)問(wèn)題上,而不是試圖理解代碼在做什么。
我們已經(jīng)知道了什么是設(shè)計(jì)模式和它的重要性,下面我們深入研究一下 JavaScript 中的 7 種設(shè)計(jì)模式。
模塊是一段獨(dú)立的代碼,因此我們可以更新模塊而不會(huì)影響代碼的其它部分。模塊還允許我們通過(guò)為變量創(chuàng)建單獨(dú)的作用域來(lái)避免命名空間污染。當(dāng)它們與其它代碼解耦時(shí),我們還可以在其它項(xiàng)目中重用模塊。
模塊是任何現(xiàn)代 JavaScript 應(yīng)用程序不可或缺的一部分,有助于保持代碼干凈,獨(dú)立和有條理。在 JavaScript 中有許多方法可以創(chuàng)建模塊,其中一種是模塊模式。
與其它編程語(yǔ)言不同,JavaScript 沒(méi)有訪問(wèn)修飾符,也就是說(shuō),你不能將變量聲明為私有的或公共的。因此,模塊模式也可用來(lái)模擬封裝的概念。
模塊模式使用 IIFE(立即調(diào)用的函數(shù)表達(dá)式),閉包和函數(shù)作用域來(lái)模擬封裝的概念。例如:
const myModule = (function() {
const privateVariable = 'Hello World';
function privateMethod() {
console.log(privateVariable);
}
return {
publicMethod: function() {
privateMethod();
}
}
})();
myModule.publicMethod();
由于是 IIFE 因此代碼會(huì)被立即執(zhí)行,并將返回對(duì)象賦值給了 myModule 變量。由于閉包,即使在 IIFE 完成后,返回的對(duì)象仍可以訪問(wèn) IIFE 內(nèi)部定義的函數(shù)和變量。
因此,IIFE 內(nèi)部定義的變量和函數(shù)對(duì)外部是看不見(jiàn)的,從而使其成為 myModule 模塊的私有成員。
執(zhí)行代碼后,myModule 變量看起來(lái)像下面所示:
const myModule = {
publicMethod: function() {
privateMethod();
}};
因此當(dāng)我們調(diào)用 publicMethod() 時(shí)候,它將調(diào)用 privateMethod() 例如:
// Prints 'Hello World'
module.publicMethod();
揭示模塊模式是 Christian Heilmann 對(duì)模塊模式的略微改進(jìn)。模塊模式的問(wèn)題在于,我們必須創(chuàng)建新的公共函數(shù)才能調(diào)用私有函數(shù)和變量。
在這種模式下,我們將返回的對(duì)象的屬性映射到要公開(kāi)暴露的私有函數(shù)上。這就是為什么將其稱為揭示模塊模式。例如:
const myRevealingModule = (function() {
let privateVar = 'Peter';
const publicVar = 'Hello World';
function privateFunction() {
console.log('Name: '+ privateVar);
}
function publicSetName(name) {
privateVar = name;
}
function publicGetName() {
privateFunction();
}
/** reveal methods and variables by assigning them to object properties */
return {
setName: publicSetName,
greeting: publicVar,
getName: publicGetName
};
})();
myRevealingModule.setName('Mark');
// prints Name: Mark
myRevealingModule.getName();
這種模式讓我們更容易知道哪些函數(shù)和變量是公共的,無(wú)形中提高了代碼的可讀性。執(zhí)行代碼后 myRevealingModule 看起來(lái)像下所示:
const myRevealingModule = {
setName: publicSetName,
greeting: publicVar,
getName: publicGetName
};
當(dāng)我們調(diào)用 myRevealingModule.setName('Mark') 時(shí),實(shí)際調(diào)用了內(nèi)部的 publicSetName。當(dāng)調(diào)用 myRevealingModule.getName() 時(shí),實(shí)際調(diào)用了內(nèi)部的 publicGetName 例如:
myRevealingModule.setName('Mark');
// prints Name: Mark
myRevealingModule.getName();
與模塊模式相比,揭示模塊模式的優(yōu)勢(shì)有:
在 ES6 之前,JavaScript 沒(méi)有內(nèi)置模塊,因此開(kāi)發(fā)人員必須依靠第三方庫(kù)或模塊模式來(lái)實(shí)現(xiàn)模塊。但是自從 ES6,JavaScript 內(nèi)置了模塊。
ES6 的模塊是以文件形式存儲(chǔ)的。每個(gè)文件只能有一個(gè)模塊。默認(rèn)情況下,模塊內(nèi)的所有內(nèi)容都是私有的。通過(guò)使用 export 關(guān)鍵字來(lái)暴露函數(shù)、變量和類。模塊內(nèi)的代碼始終在嚴(yán)格模式下運(yùn)行。
有兩種方法可以導(dǎo)出函數(shù)和變量聲明:
// utils.js
export const greeting = 'Hello World';
export function sum(num1, num2) {
console.log('Sum:', num1, num2);
return num1 + num2;
}
export function subtract(num1, num2) {
console.log('Subtract:', num1, num2);
return num1 - num2;
}
// This is a private function
function privateLog() {
console.log('Private Function');
}
// utils.js
function multiply(num1, num2) {
console.log('Multiply:', num1, num2);
return num1 * num2;
}
function divide(num1, num2) {
console.log('Divide:', num1, num2);
return num1 / num2;
}
// This is a private function
function privateLog() {
console.log('Private Function');
}
export {multiply, divide};
與導(dǎo)出模塊相似,有兩種使用 import 關(guān)鍵字導(dǎo)入模塊的方法。例如:
// main.js
// importing multiple items
import { sum, multiply } from './utils.js';
console.log(sum(3, 7));
console.log(multiply(3, 7));
// main.js
// importing all of module
import * as utils from './utils.js';
console.log(utils.sum(3, 7));
console.log(utils.multiply(3, 7));
// utils.js
function sum(num1, num2) {
console.log('Sum:', num1, num2);
return num1 + num2;
}
function multiply(num1, num2) {
console.log('Multiply:', num1, num2);
return num1 * num2;
}
export {sum as add, multiply};
// main.js
import { add, multiply as mult } from './utils.js';
console.log(add(3, 7));
console.log(mult(3, 7));
一個(gè)單例對(duì)象是只能實(shí)例化一次的對(duì)象。如果不存在,則單例模式將創(chuàng)建類的新實(shí)例。如果存在實(shí)例,則僅返回對(duì)該對(duì)象的引用。重復(fù)調(diào)用構(gòu)造函數(shù)將始終獲取同一對(duì)象。
JavaScript 是一直內(nèi)置單例的語(yǔ)言。我們只是不稱它們?yōu)閱卫覀兎Q它們?yōu)閷?duì)象字面量。例如:
const user = {
name: 'Peter',
age: 25,
job: 'Teacher',
greet: function() {
console.log('Hello!');
}
};
因?yàn)?JavaScript 中的每個(gè)對(duì)象都占用一個(gè)唯一的內(nèi)存位置,并且當(dāng)我們調(diào)用該 user 對(duì)象時(shí),實(shí)際上是在返回該對(duì)象的引用。
如果我們嘗試將 user 變量復(fù)制到另一個(gè)變量并修改該變量。例如:
const user1 = user;
user1.name = 'Mark';
我們將看到兩個(gè)對(duì)象都被修改,因?yàn)?JavaScript 中的對(duì)象是通過(guò)引用而不是通過(guò)值傳遞的。因此,內(nèi)存中只有一個(gè)對(duì)象。例如:
// prints 'Mark'
console.log(user.name);
// prints 'Mark'
console.log(user1.name);
// prints true
console.log(user === user1);
可以使用構(gòu)造函數(shù)來(lái)實(shí)現(xiàn)單例模式。例如:
let instance = null;
function User() {
if(instance) {
return instance;
}
instance = this;
this.name = 'Peter';
this.age = 25;
return instance;
}
const user1 = new User();
const user2 = new User();
// prints true
console.log(user1 === user2);
調(diào)用此構(gòu)造函數(shù)時(shí),它將檢查 instance 對(duì)象是否存在。如果對(duì)象不存在,則將 this 變量分配給 instance 變量。如果該對(duì)象存在,則只返回該對(duì)象。
單例也可以使用模塊模式來(lái)實(shí)現(xiàn)。例如:
const singleton = (function() {
let instance;
function init() {
return {
name: 'Peter',
age: 24,
};
}
return {
getInstance: function() {
if(!instance) {
instance = init();
}
return instance;
}
}
})();
const instanceA = singleton.getInstance();
const instanceB = singleton.getInstance();
// prints true
console.log(instanceA === instanceB);
在上面的代碼中,我們通過(guò)調(diào)用 singleton.getInstance 方法來(lái)創(chuàng)建一個(gè)新實(shí)例。如果實(shí)例已經(jīng)存在,則此方法僅返回該實(shí)例。如果該實(shí)例不存在,則通過(guò)調(diào)用該 init() 函數(shù)創(chuàng)建一個(gè)新實(shí)例。
工廠模式使用工廠方法創(chuàng)建對(duì)象而不需要指定具體的類或構(gòu)造函數(shù)的模式。
工廠模式用于創(chuàng)建對(duì)象而不需要暴露實(shí)例化的邏輯。當(dāng)我們需要根據(jù)特定條件生成不同的對(duì)象時(shí),可以使用此模式。例如:
class Car{
constructor(options) {
this.doors = options.doors || 4;
this.state = options.state || 'brand new';
this.color = options.color || 'white';
}
}
class Truck {
constructor(options) {
this.doors = options.doors || 4;
this.state = options.state || 'used';
this.color = options.color || 'black';
}
}
class VehicleFactory {
createVehicle(options) {
if(options.vehicleType === 'car') {
return new Car(options);
} else if(options.vehicleType === 'truck') {
return new Truck(options);
}
}
}
這里,創(chuàng)建了一個(gè) Car 和一個(gè) Truck 類(具有一些默認(rèn)值),該類用于創(chuàng)建新的 car 和 truck對(duì)象。而且定義了一個(gè)VehicleFactory 類,用來(lái)根據(jù) options 對(duì)象中的 vehicleType 屬性來(lái)創(chuàng)建和返回新的對(duì)象。
const factory = new VehicleFactory();
const car = factory.createVehicle({
vehicleType: 'car',
doors: 4,
color: 'silver',
state: 'Brand New'
});
const truck= factory.createVehicle({
vehicleType: 'truck',
doors: 2,
color: 'white',
state: 'used'
});
// Prints Car {doors: 4, state: "Brand New", color: "silver"}
console.log(car);
// Prints Truck {doors: 2, state: "used", color: "white"}
console.log(truck);
我為類 VehicleFactory 創(chuàng)建了一個(gè)新的 factory 對(duì)象。然后,我們通過(guò)調(diào)用 factory.createVehicle 方法并且傳遞 options 對(duì)象,其 vehicleType 屬性可能為 car 或者 truck 來(lái)創(chuàng)建新 Car 或 Truck 對(duì)象。
裝飾器模式用于擴(kuò)展對(duì)象的功能,而無(wú)需修改現(xiàn)有的類或構(gòu)造函數(shù)。此模式可用于將特征添加到對(duì)象中,而無(wú)需修改底層的代碼。
此模式的一個(gè)簡(jiǎn)單示例為:
function Car(name) {
this.name = name;
// Default values
this.color = 'White';
}
// Creating a new Object to decorate
const tesla= new Car('Tesla Model 3');
// Decorating the object with new functionality
tesla.setColor = function(color) {
this.color = color;
}
tesla.setPrice = function(price) {
this.price = price;
}
tesla.setColor('black');
tesla.setPrice(49000);
// prints black
console.log(tesla.color);
這種模式的一個(gè)更實(shí)際的例子是:
假設(shè)汽車的成本取決于其功能的數(shù)量。如果沒(méi)有裝飾器模式,我們將不得不為不同的功能組合創(chuàng)建不同的類,每個(gè)類都有一個(gè) cost 方法來(lái)計(jì)算成本。例如:
class Car() {
}
class CarWithAC() {
}
class CarWithAutoTransmission {
}
class CarWithPowerLocks {
}
class CarWithACandPowerLocks {
}
但是,通過(guò)裝飾器模式,我們可以創(chuàng)建一個(gè)基類 car 并且通過(guò)裝飾器函數(shù)給不同的對(duì)象添加對(duì)應(yīng)的成本邏輯。
class Car {
constructor() {
// Default Cost
this.cost = function() {
return 20000;
}
}
}
// Decorator function
function carWithAC(car) {
car.hasAC = true;
const prevCost = car.cost();
car.cost = function() {
return prevCost + 500;
}
}
// Decorator function
function carWithAutoTransmission(car) {
car.hasAutoTransmission = true;
const prevCost = car.cost();
car.cost = function() {
return prevCost + 2000;
}
}
// Decorator function
function carWithPowerLocks(car) {
car.hasPowerLocks = true;
const prevCost = car.cost();
car.cost = function() {
return prevCost + 500;
}
}
首先,我們創(chuàng)建了小轎車的基類 Car。然后針對(duì)要添加的特性創(chuàng)建了裝飾器并且此裝飾器以 Car 對(duì)象為參數(shù)。然后通過(guò)返回更新后的小汽車成本來(lái)覆蓋對(duì)象的成本函數(shù),且添加了一個(gè)用來(lái)標(biāo)識(shí)某個(gè)特性是否已經(jīng)被添加的屬性。
要添加新的功能,我們只需要像下面一樣就可以:
const car = new Car();
console.log(car.cost());
carWithAC(car);
carWithAutoTransmission(car);
carWithPowerLocks(car);
最后,我們可以像這樣計(jì)算汽車的成本:
// Calculating total cost of the car
console.log(car.cost());
我們已經(jīng)了解了 JavaScript 中使用的各種設(shè)計(jì)模式,但是這里沒(méi)有涉及到可以用 JavaScript 實(shí)現(xiàn)的設(shè)計(jì)模式。
盡管了解各種設(shè)計(jì)模式很重要,但不要過(guò)度使用它們也同樣重要。在使用設(shè)計(jì)模式之前,你應(yīng)該仔細(xì)考慮你的問(wèn)題是否適合該設(shè)計(jì)模式。要知道某個(gè)模式是否適合你的問(wèn)題,應(yīng)該好好研究該設(shè)計(jì)模式以及它的應(yīng)用。
最后,歡迎優(yōu)秀的你加入 HelloGitHub 的「譯文亦舞」系列,讓你的才華舞動(dòng)起來(lái)!把優(yōu)秀的文章分享給更多的人。要求:
關(guān)注 HelloGitHub 頭條號(hào)第一時(shí)間收到推送
*請(qǐng)認(rèn)真填寫需求信息,我們會(huì)在24小時(shí)內(nèi)與您取得聯(lián)系。