'client' is never reassigned. Use 'const' instead
117 let rawdata = fs.readFileSync(jsonFile);
118 let person = JSON.parse(rawdata);
119 console.log(person.START_JUMP)
120 let client = Client.createClient(ALIYUN.ACCESS_KEY, ALIYUN.ACCESS_KEY_SECRET);121 await Client.BatchPubSample(client, ALIYUN.PRODUCT_KEY, ALIYUN.IOT_INSTANCE_ID, base64encode(JSON.stringify(person.START_JUMP)), topic, sn);
122 }
123}
'person' is never reassigned. Use 'const' instead
115 const topic = "get";
116 const sn = ALIYUN.DEVICE_NAME;
117 let rawdata = fs.readFileSync(jsonFile);
118 let person = JSON.parse(rawdata);119 console.log(person.START_JUMP)
120 let client = Client.createClient(ALIYUN.ACCESS_KEY, ALIYUN.ACCESS_KEY_SECRET);
121 await Client.BatchPubSample(client, ALIYUN.PRODUCT_KEY, ALIYUN.IOT_INSTANCE_ID, base64encode(JSON.stringify(person.START_JUMP)), topic, sn);
'rawdata' is never reassigned. Use 'const' instead
114 static async publishJumpingOrder() {
115 const topic = "get";
116 const sn = ALIYUN.DEVICE_NAME;
117 let rawdata = fs.readFileSync(jsonFile);118 let person = JSON.parse(rawdata);
119 console.log(person.START_JUMP)
120 let client = Client.createClient(ALIYUN.ACCESS_KEY, ALIYUN.ACCESS_KEY_SECRET);
'client' is never reassigned. Use 'const' instead
106 let rawdata = fs.readFileSync(jsonFile);
107 let person = JSON.parse(rawdata);
108 console.log(person.GROUPING)
109 let client = Client.createClient(ALIYUN.ACCESS_KEY, ALIYUN.ACCESS_KEY_SECRET);110 await Client.BatchPubSample(client, ALIYUN.PRODUCT_KEY, ALIYUN.IOT_INSTANCE_ID, base64encode(JSON.stringify(person.GROUPING)), topic, sn);
111 }
112
'person' is never reassigned. Use 'const' instead
104 const topic = "get";
105 const sn = ALIYUN.DEVICE_NAME;
106 let rawdata = fs.readFileSync(jsonFile);
107 let person = JSON.parse(rawdata);108 console.log(person.GROUPING)
109 let client = Client.createClient(ALIYUN.ACCESS_KEY, ALIYUN.ACCESS_KEY_SECRET);
110 await Client.BatchPubSample(client, ALIYUN.PRODUCT_KEY, ALIYUN.IOT_INSTANCE_ID, base64encode(JSON.stringify(person.GROUPING)), topic, sn);
'rawdata' is never reassigned. Use 'const' instead
103 static async publishGroupsOrder() {
104 const topic = "get";
105 const sn = ALIYUN.DEVICE_NAME;
106 let rawdata = fs.readFileSync(jsonFile);107 let person = JSON.parse(rawdata);
108 console.log(person.GROUPING)
109 let client = Client.createClient(ALIYUN.ACCESS_KEY, ALIYUN.ACCESS_KEY_SECRET);
'response' is never reassigned. Use 'const' instead
82 deviceName
83 ],
84 });
85 let response = await client.batchPub(request); 86 tea_console_1.default.log(tea_util_1.default.toJSONString($tea.toMap(response)));
87 }
88 catch (error) {
'request' is never reassigned. Use 'const' instead
67 */
68 static async BatchPubSample(client, productKey, iotInstanceId, messageContent, topicShortName, deviceName) {
69 try {
70 let request = new $Iot.BatchPubRequest({ 71 // 物联网平台实例ID
72 iotInstanceId: iotInstanceId,
73 // 产品ProductKey
'config' is never reassigned. Use 'const' instead
46 * @throws Exception
47 */
48 static createClient(accessKeyId, accessKeySecret) {
49 let config = new $OpenApi.Config({}); 50 // 您的AccessKey ID
51 config.accessKeyId = accessKeyId;
52 // 您的AccessKey Secret
'content' is never reassigned. Use 'const' instead
26 let msg = context.message;
27 let messageId = msg.message_id;
28 let topic = msg.application_properties.topic;
29 let content =JSON.parse(Buffer.from(msg.body.content).toString().replace(/\'/g, '"'));30 if (topic.indexOf('/user/update') !== -1) {
31 console.log("\nTopic: " + topic)
32 if (content.subType === "SCAN") {
'messageId' is never reassigned. Use 'const' instead
24//接收云端推送消息的回调函数。
25container.on('message', function (context) {
26 let msg = context.message;
27 let messageId = msg.message_id;28 let topic = msg.application_properties.topic;
29 let content =JSON.parse(Buffer.from(msg.body.content).toString().replace(/\'/g, '"'));
30 if (topic.indexOf('/user/update') !== -1) {
'msg' is never reassigned. Use 'const' instead
23
24//接收云端推送消息的回调函数。
25container.on('message', function (context) {
26 let msg = context.message;27 let messageId = msg.message_id;
28 let topic = msg.application_properties.topic;
29 let content =JSON.parse(Buffer.from(msg.body.content).toString().replace(/\'/g, '"'));
'topic' is never reassigned. Use 'const' instead
25container.on('message', function (context) {
26 let msg = context.message;
27 let messageId = msg.message_id;
28 let topic = msg.application_properties.topic;29 let content =JSON.parse(Buffer.from(msg.body.content).toString().replace(/\'/g, '"'));
30 if (topic.indexOf('/user/update') !== -1) {
31 console.log("\nTopic: " + topic)
Description
Variables that are never re-assigned a new value after their initial declaration should be declared with the const
keyword.
This prevents the programmer from erroneously re-assigning to a read-only variable, and informs those reading the code that a variable is a constant value.
Bad Practice
let pi = Math.PI
for (let x of xs) {
use(x);
}
let { a, b } = object;
use(a, b);
Recommended
const pi = Math.PI
for (const x of xs) {
use(x);
}
const { a, b } = object;
use(a, b);