• Recommendation: Learn TypeScript early to compete in the workplace

Source: making stars ✨ | o | give a ❤ ️ attention, ❤ ️ thumb up, ❤ ️ encourages the author

I hope I can help more friends. Add me 😚 can exchange problems (not big guy, learn from each other, create a good learning environment). Which of the following do you not understand?

1. Inheritance of ES5 and ES6

  • Es5 inheritance is to create an instance object of the subclass and then add the methods of the superclass to this,Parent.apply(this)
  • Es6 inherits by creating an instance object of the parent class, this, so the parent class is called firstsuper()Method, and then modify this with the subclass’s constructor
  • Inheritance in ES5 is implemented through the stereotype or constructor mechanism
  • Es6 defines classes through the class keyword, which has constructors, and inherits classes through the extends keyword
  • The word class must be againconstructorMethod callsuperMethod, or an error is reported when creating a new instance
  • The super keyword represents an instance of the superclass, which is the this object of the superclass
  • Use this keyword only after super is called in the subclass constructor, otherwise an error is reported

The difference between innerHTML and outHTML

<div id="dadaqianduan" </div> document.getelementById ("dadaqianduan").innerhtml; Document.getelementbyid ("dadaqianduan").outerhtml; // <div id="dadaqianduan">Copy the code
  • InnerHTML Sets or gets the HTML inside the start and end tags of an object
  • OuterHTML Sets or retrieves the HTML form of an object and its content

3. Block-level binding

3.1 Var declaration and variable promotion

  • Es6 block-level binding
  • Where a variable is created depends on how you declare it, right
  • Var declarations and variable promotion
  • Variables declared with the var keyword are treated as if they were declared at the top of the function regardless of where they are actually declared, or at the top of the global scope if the declaration is not in any function (variable promotion)

Example:

Function fun(value) {if(value) {var da = "zha "; return da; } esle {return null} // da can be accessed with the value of undefined}Copy the code

If you think the variable da will be created when value is true, it will be created anyway, as shown in the following code:

function fun(value) { var da; If (value) {da = 'zha '; return da; } else { return null; }}Copy the code
  • The declaration of the DA variable is moved to the top, and the initialization is left in place
  • The above code indicates that the da variable in the else branch is also accessible, but its value will be undefined because it is not initialized

Es6 introduces block-level scopes to make variable declaration cycles more manageable

3.2 Block-level declaration

  • Block-level scope (also known as lexical scope)
  • Block-level declarations make declared variables inaccessible outside the scope of the specified block

Create:

Block-level scope:

  1. Inside a function
  2. Inside a code block

Let the statement

Let is often used in projects instead of var for variable declarations (let declarations limit the scope of variables to the current code block)

  • If you don’t need variables to be used within the entire code block, use let declarations
  • If you use the let declaration, it will not be promoted to the top of the current code block. If you want to put the let declaration at the top and use variables throughout the code block, you should use the var declaration instead
Function fun(value) {if(value) {let da = "nezha "; return da; }else{// da return null is not available here; } // da is not available here}Copy the code

If value is false, the variable will never be declared and initialized

As follows: may not repeat the statement yo ~

  • If an identifier is already defined in a code block, using the same identifier for let declarations inside the code block will cause an error
Var da = 'Nezha '; // let da = 'Nezha is handsome ';Copy the code

There is a picture and there is a truth

If you use let to declare a new variable with the same name in a nested scope, you will not get an error

var da = 12; If (true) {let da = 123; }Copy the code

Declaration of constants

  • Variables declared with const are considered constantconstant, indicating that their values cannot be changed after they have been set

So, all const variables need to be initialized:

// Const da = 12; // syntax error: const dada not initialized;Copy the code

  • Remember: constant declarations are the same as let declarations, both are block-level declarations (see above)

Example:

If (value) {const da = 'Nezha'} // da cannot be accessed hereCopy the code

In strict or non-strict mode: Assigning a constant previously declared as const throws an error

Const da = 'Da =' Is cool, Nezha '// Throws an errorCopy the code

Const declares a constant. If const is used to declare an object as follows:

A const declaration prevents changes to the binding and value of the variable itself, meaning that a const declaration does not prevent changes to the members of the variable.

Prevent: variable binding, variable value modification

Do not block: variable members from being modified

Example:

Const dada = {string: 'Dadaqianduan. cn dream of a hundred million girls'}; // Normal dada.string = 'Nezha: A Girl's Dream '; // Throw an error dada = {string: 'Nezha, you are dreaming'};Copy the code

  • Const prevents changes to variable bindings
  • Const does not prevent changes to a member value

Temporary dead zone

What is a temporary dead zone? As mentioned earlier, a variable declared using a let or const cannot be accessed until it reaches the declaration, which would result in a reference error. Even when it’s safe, it’s the same.

As follows:

if(value) { console.log(typeof da); // let da = 'daguo is so handsome '; }Copy the code

When the JS engine examines a code block and finds a variable declaration, it pushes the declaration to the top of the function or global scope in the case of var, and puts the declaration in a temporary dead zone in the case of let or const.

Any attempt to access a variable within a transient dead zone results in a Runtime error. A variable is removed from the temporary dead zone and is safe to use only when its declaration statement is executed.

Example:

Use Typeof on the variable outside of the code block where it is defined, although the result may not be expected:

console.log(typeof da); // 'undefined'

if(true) {
 let da = 'dadaqianduan';
}
Copy the code

3.3 Block-level binding in loops

The function inside the loop

// Because the var declaration causes the variable to be promoted. for (var i = 0; i < 10; i++) { ... } // I is still accessible here console.log(I); / / 10Copy the code
for (let i = 0; i < 10; i++) { ... } // I is not accessible here, throw error console.log(I);Copy the code
  • Call the function expression immediately:
for(var i=1; i<=5; i++) { setTimeout(() => { console.log(i) }, i*1000) }Copy the code

Var is used to declare variable I in the for loop, and there is a variable promotion problem in var, and the same variable is used in all six loops. Therefore, when the delay function in setTimeout starts to execute, the loop has already ended, and I =6 at this point, so six 6’s will be printed.

The variable I is shared in each iteration of the loop, meaning that the functions created within the loop all have references to the same variable.

Closures can solve this problem:

for(var i=1; i<=5; i++) { (function(j){ setTimeout(() => { console.log(j) }, j* 1000) })(i) }Copy the code
  • Use immediate call function expressions (IIFEs) within the loop to force the creation of a new copy of the variable in each iteration

  • Use the third argument of setTimeout

for(var i=1; i<=5; i++) { setTimeout((j) => { console.log(j) }, i* 1000, i) }Copy the code
  • Define I using let
for(let i=1; i<=5; i++) { setTimeout(() => { console.log(i) }, i*1000) }Copy the code

The let declaration within the loop

  • In each iteration, a new variable with the same name is created and initialized.
  • The let declaration creates a new I variable each time in the loop, so functions created inside the loop get their own copies of I
  • The value of each copy of I is determined each time the variable is declared through the loop iteration

Example:

var arr = [],
object = {
a: 1,
b: 2,
c: 3
};
for(let key in object) {
 arr.push(function(){
  console.log(key);
 });
}

arr.forEach(function(func){
 func(); // a,b,c
});
Copy the code

  • Each time through the loop, a new key variable binding is created, and each function can have its own copy of the key variable, with the result that each function outputs a different value

A constant declaration within a loop

Example:

// Throw an error for(const I = 0; i < 10; i++){.. }Copy the code

The for – or the for – in

var arr = [], object = { a: 1, b: 2, c: 3 }; For (const key in object) {arr.push(function(){console.log(key); }); } arr.forEach(function(func){ func(); // a,b,c });Copy the code

Note that with const declarations, you cannot change the value. The loop creates a new variable binding for each iteration, rather than trying to change the value of an already bound variable.

3.4 Global block-level binding

With var, in the global scope, it creates a new global variable and becomes a property of the global object. It is possible that when you use var, it may inadvertently overwrite an existing global property. Using the var declaration, it is defined as a global variable and immediately becomes an attribute of the window.

If you use let or const in the global scope, new bindings will be created in the global scope, but will not be added to the global object. You cannot overwrite a global variable with let or const. You can only use it for masking.

Description:

  • Temporary dead zones exist due to block-level binding(TDZ)Attempting to access a location before declaring it results in an error.
  • Let and const can create a new binding for each iteration in for-in and for-of, indicating that the function created in the body of the loop can use the value of the loop variable bound by the current iteration.
  • Do not use the variable value at the end of the loop as you would with var.
  • A const let declaration in a for loop is an error.

4. Difference between innerText and innerContent

  1. textContentWill getstyle="display:none, whileinnerTextDon’t
  2. textContentWill getstyleTag inside the text, andinnerTextDon’t
  3. textContentDon’t ignorehtmlFormat, directly output text without newlines
  4. innerTextA separate line is created based on the element inside the tag
  5. innerTextA separate line is created based on the element inside the tag
  6. innerTextrightIEThe compatibility is good
  7. textContentIt is standard but only supportedIE8+The above browsers

5.el.childrenandel.childNodesThe difference between

  1. el.children, returns all of the specified nodeelementChild node, that is, returnNode element
  2. el.childNodes, returns all children of the specified node, includingNode elements and text elements

6. JavaScript syntax

  1. Methods:JavaScriptPut the code in the document<head>In the tag<scripttags
  2. Method: in the document<head>Part of it<script>Tag and put it onsrcProperty points to the file
  3. Methods: the<script>Tags are placed at the end of the HTML document,</body>TAB (this will make the browser load the page faster)
  4. JavaScript variable names can contain letters, numbers, dollar signs, and underscores (but the first character cannot be a number)
  5. Generally, the hump format is the preferred naming format for function names, method names, and object attribute names.
  6. Several data types in JavaScript: strings, values, Booleans, arrays, and objects.
  7. The predefined objects provided by the browser are called host objects.
  8. typeofThe operator can tell us whether its operand is a string, number, function, Boolean, or object.
  • String: A string consists of zero or more characters. Characters include (but are not limited to) letters, numbers, punctuation marks, and Spaces.
  • If the string contains double quotes, place the entire string in single quotes; If the string contains single quotes, place the entire string in double quotes.
  • The substitution of objects for traditional arrays means that elements can be referred to by their names rather than by subscript numbers.

Variable scope: global, local.

  1. Global variables that can be referenced anywhere in the script. Once you declare a global variable in a script, you can refer to it from anywhere in the script, including inside the function. Global variables are scoped to the entire script.
  2. A local variable, which exists only inside the function in which it is declared, cannot be referred to outside that function. The scope of local variables is limited to a particular function.

7.DOM

  1. getElementById
  2. getElementsByTagName
  3. getElementsByClassName
  4. getAttribute
  5. setAttribute

Objects in the JavaScript language

  1. User-defined objects, objects created by programmers themselves
  2. Built-in objects, objects built into the JavaScript language
  3. Host object, an object provided by the browser
  • The Window object, the browser window itself, the properties and methods of the entire object are often called BOM, the browser object model.
  • Node: element node, text node, attribute node

Method of obtaining element node: by element ID, by tag name, by class name

  1. getElementById, this method will return one given thatidThe element node of the property valueCorresponding object.document.getElementById(id)
  2. getElementsByTagName, this method returnsAn array of objectsEach object corresponds to an element in the document with a given label.element.getElementsByTagName(tag)
  3. getElementsByClassName, which accesses elements by the Class name in the Class attribute

Get and numeric attributes:

  1. getAttributeThe method is used to get the property –object.getAttribute(attribute)
  2. setAttributeMethod can be used to change the value of the attribute node –object.setAttribute(attribute,value)

Example:

var node = document.getElementsByTagName("p");
for(let i=0, i<node.length; i++){
 console.log(node[i].getAttribute("title"));
}
Copy the code
var node = document.getElementsByTagName("p");
node.setAttribute("title","dadaqianduan.cn");
Copy the code

8.aThe label

  • targetAttribute decision
  • _blankOpen the linked document in a new window
  • _selfBy default, the linked document is opened in the same framework

Function of 9.

Functions with default values for arguments:

// es5
function Fun(da, da2) {
 da = da || 'dadaqianduan';
 da2 = da2 || '1024bibi.com';
}
Copy the code

Typeof to check the typeof the parameter:

function fun(da) { da = (typeof da ! == 'undefined") ? da : 'dadaqianduan'; }Copy the code
Callback = function(){}) {}Copy the code

How do parameter defaults affect arguments objects

  • The Arguments object will differ when using parameter defaults
  • In non-strict mode, the Arguments object is always updated to reflect changes in the arguments
  • Es5 strict mode no longer reflects changes in the name parameter

As follows:

function fn(a) { console.log(a === arguments[0]); A = 'dada front '; console.log(a === arguments[0]); } fn('dadaqianduan');Copy the code

function fn(a) { "use strict"; console.log(a === arguments[0]); A = 'dada front '; console.log(a === arguments[0]); } fn('dadaqianduan');Copy the code

Parameter default value expression

Example:

function getValue() { return 1; } function add(a, b = getValue()) { return a + b; } the console. The log (add (1, 1)); // 2 console.log(add(2); / / 3Copy the code
let value = 5; function getValue() { return value++; } function add(a,b=getValue()) { return a+b; } the console. The log (add (1, 1)); // 2 console.log(add(1)); // 6 console.log(add(1)); / / 7Copy the code
function add(a,b=a) { return a + b; } the console. The log (add (1, 1)); console.log(add(1));Copy the code
function getValue(value) { return value + 5; } function add(a, b = getValue(a)) { return a + b; } the console. The log (add (1, 1)); // 2 console.log(add(1)); / / 7Copy the code
function add(a = b, b) { return a + b; } the console. The log (add (1, 1)); // 2 console.log(add(undefined,1)); // Throw an errorCopy the code

Parameter Default temporary dead zone

  • The function creates a new identifier binding for each argument, which is not allowed to be accessed until initialized or an error is thrown.

An unnamed parameter in ES5

Example:

function da(object) { let result = Object.create(null); for(let i = 1, len = arguments.length; i<len; i++) { result[arguments[i]] = object[arguments[i]]; } return result; } let book = { a: '1', b: '2', c: '3' }; let da1 = da(book, 'a', 'b'); console.log(da1.a); // 1 console.log(da2.b); / / 2Copy the code

The remaining parameters

The remaining parameters consist of three points (…). Specified with a named parameter immediately following.

function fn(object, ... keys) { let result = Object.reate(null); for(let i = 0, len = keys.length; i<len; i++) { result[key[i]] = object[keys[i]]; } return result; }Copy the code
  • Residual argument: A function can have only one residual argument, and it must be placed last.
  • Remaining parameters: cannot be used in setter properties of object literals
Let object = {// syntax error: cannot use the remaining parameter set name(... Value) {// Some operations}};Copy the code
  • The Arguments object reflects the arguments passed in when the function is called
  • The Arguments object always correctly reflects the arguments to the function being passed
function fn(... args) { console.log(args.length); console.log(arguments.length); console.log(args[0], arguments[0]); console.log(args[1], arguments[1]); } fn("a","b"); // 2 // 2 // a a // b bCopy the code

Enhancements to function constructors (es6 default and remaining arguments)

var add = new Function("a", "b", "return a + b"); The console. The log (add (1, 1)); // 2 var da = new Function("a", "b=a", "return a+b"); The console. The log (da (1, 1)); // 2 console.log(da(1)); / / 2Copy the code

Extended operator

Example:

// es5 let arr = [1,2,3,4,5]; console.log(Math.max.apply(Math, arr)); / / 5Copy the code
// es6 let arr = [1,2,3,4,5]; console.log(Math.max(... values)); // 5 let arr2 = [-2,-3,-4]; console.log(Math.max(... arr2, 0)); / / 0Copy the code

Es6 function name attribute

Example:

function da() {}
console.log(da.name); // da

var dada = function() {}
console.log(dada.name); // dada
Copy the code

A special case of the name attribute

Clarify the dual purpose of the function: when new is used, this inside the function is a new object and is returned as the function value.

When a function is not called with new, the call method is executed, running the body of the function shown in the code.

When the function is called with new, the Construct method is executed, creating a new object called a new target and executing the function body using the new target as this.

Es6 introduces the new.target meta-attribute

function Fun(value) { if(this instanceof Fun) { this.value = value; } else { throw new Error("dadaqianduan"); } } var da = new Fun("dada"); var dadaqianduan = Fun("123"); / / an errorCopy the code
function Fun(value) {
 if(this instanceof Fun) { 
  this.value = value;
 } else {
  throw new Error("dadaqianduan");
 }
}
var da = new Fun("dada");
var dadaqianduan = Fun.call(da, "dadaqianduan"); // ok
Copy the code
Function Fun(value) {// If (typeof new.target! == "undefined") { this.value = value; }else{ throw new Error("dadaqianduan.cn"); } } var da = new Fun("jeskson"); var da2 = Fun.call(da, 'jeskson'); / / an errorCopy the code
function Fun(value) { if(new.target === Fun) { this.value = value; }else{ throw new Error("dadaqianduan.cn"); } } function Da(value) { Fun.call(this, name); } var person = new Fun("dadaqianduan.cn"); var person1 = new Da("dadaqianduan.cn"); / / an errorCopy the code

10. Transmission between UNI-APP and Bluetooth device

  1. Example Initialize the Bluetooth module
  2. Search for Bluetooth devices
  3. Connect bluetooth device
  4. Select Device Service
  5. Gets the eigenvalues of the service
  6. Subscription eigenvalue
  7. To send data
  8. Send a success
  • Uni. OpenBluetoothAdapter (OBJECT)

  • Began to search the bluetooth devices uni. StartBluetoothDevicesDiscovery (OBJECT)

  • Found that peripheral uni. OnBluetoothDeviceFound (the CALLBACK)

  • Stop searching for nearby bluetooth peripherals uni. StopBluetoothDevicesDiscovery (OBJECT)

  • Uni. CreateBLEConnection (OBJECT)

  • Uni.getble Device services (OBJECT)

  • Get the bluetooth feature uni. GetBLEDeviceCharacteristics (OBJECT)

  • Enable the notify function when the characteristic values of a Bluetooth device change

uni.notifyBLECharacteristicValueChange(OBJECT)

  • Monitor eigenvalue changes of low power Bluetooth devices

uni.onBLECharacteristicValueChange(CALLBACK)

Initialize bluetooth (check whether bluetooth is turned on)

Uni. OpenBluetoothAdapter (= > {{success: (res) / / has opened the uni. GetBluetoothAdapterState ({/ / bluetooth state of matching success: (res1) = > {the console. The log (res1, "the machine equipment bluetooth has opened") / / began to search for bluetooth devices. This startBluetoothDeviceDiscovery ()}, Fail :(error)=>{uni.showtoast ({icon:' None ',title:' Check whether bluetooth is on '}}); }, fail: (err) = > {/ / not to open the uni. ShowToast ({icon: 'none', the title: 'see if mobile phone bluetooth open'}); }})Copy the code

Start searching for bluetooth devices

startBluetoothDeviceDiscovery() { uni.startBluetoothDevicesDiscovery({ success:(res) => { StartBluetoothDevicesDiscovery console. The log (' success ', res) / / found equipment enclosing onBluetoothDeviceFound ()}, Fail :(err) => {console.log(err, 'error message '); }})}Copy the code

Discover a device and obtain the device ID

OnBluetoothDeviceFound () {uni. OnBluetoothDeviceFound ((res) = > {/ / search to the equipment stored if(this.list.indexOf(res.devices[0].deviceId) === -1){ this.list.push(res.devices[0].deviceId) } }) }Copy the code

Click to select the device you want to connect to connect the Bluetooth device

CreateBLEConnection (deviceId) {this.deviceId = deviceId // Connect bluetooth uni. CreateBLEConnection ({deviceId: Enclosing deviceId, success: (res) = > {enclosing stopBluetoothDeviceDiscovery () the console. The log (" bluetooth connection success ")}, Fail :(res) =>{console.log(' bluetooth connection failed ',res)}})}Copy the code

When the connection is successful, stop searching for the device

stopBluetoothDevicesDiscovery(){ uni.stopBluetoothDevicesDiscovery({ success: E => {this.loading = false console.log(' stop searching for Bluetooth devices :' + e.rrmsg); }, fail: e=> {console.log(' stop search bluetooth device failed, error code: '+ e.rrcode); }}); }Copy the code

To obtain all services of bluetooth device,setTimeout waits for one second and then obtains them. If we directly obtain them, we may fail to obtain them

/ / get the bluetooth feature getBLEDeviceCharacteristics () {the console. The log (" into the characteristics of "); SetTimeout () = > {uni. GetBLEDeviceCharacteristics ({/ / deviceId need here has been through createBLEConnection establish links with the corresponding equipment DeviceId: enclosing deviceId, / / the serviceId need to obtain serviceId in getBLEDeviceServices interface: this. ServiceId, Success: (res) = > {the console. The log (res, 'characteristics getBLEDeviceCharacteristics) enclosing characteristics = res. Characteristics The console. The log (enclosing characteristics) / / cycle all uuid res. Characteristics. The forEach ((item) = > {the if (item. Uuid. IndexOf (" LD ")! If (* * * * * * *){console.log('characteristicId:', item.uuid); Suggest using setTimeout interval of this method is called this. NotifyBLECharacteristicValueChange (item. Uuid)}})}, fail:(res)=>{ console.log(res) } }) },1000) },Copy the code

Enable the notify function when the characteristic values of a Bluetooth device change

  • Start notify to know our current bluetooth read and write status.
Properties: {" read ": true, // Read" write ": true, // write" notify ": true, // Broadcast" indicate ": false}Copy the code
/ / enable notifyBLECharacteristicValueChange notify function (characteristicId) {the console. The log (characteristicId, 'characteristicId) uni.notifyBLECharacteristicValueChange({ state: True, / / enable deviceId notify function: enclosing deviceId, serviceId: this. ServiceId, characteristicId: characteristicId, success:(res)=> { console.log(res) // console.log(this.characteristicId) console.log('notifyBLECharacteristicValueChange  success', res.errMsg) }, fail:(res)=> { console.log('notifyBLECharacteristicValueChange success2', res.errMsg) } }) },Copy the code

Waiting for:

GetBLEDeviceServices (){setTimeout(()=>{uni.getbleDeviceservices ({deviceId: this.deviceid, success:(res)=>{ console.log('device services:', res) res.services.forEach((item)=>{ if(item.uuid.indexOf("LD")! =-1){ // this.serviceId = item.uuid; This. Code.store.mit ("upserviceId",item.uuid) console.log(this.serviceid) Uni. OnBLECharacteristicValueChange ((res) = > {the console. The log (" success "monitoring, res) / / res. The value is ArrayBuffer type, officials gave a method to turn hexadecimal, We cannot operate this. Shiliu = this. Ab2hex (res) value)}) enclosing getBLEDeviceCharacteristics ()}})}})}, 1000)}Copy the code

Read Bluetooth device

Example:

/ / in the page load when initializing bluetooth adapter uni. OpenBluetoothAdapter/finished/initialization start searching this. StartBluetoothDeviceDiscovery () the console. The log (" started to search for intelligent equipment "); uni.startBluetoothDevicesDiscovery success: res => { self.onBluetoothDeviceFound(); }, onBluetoothDeviceFound console.log(' Start listening for new device found event '); stopBluetoothDevicesDiscoveryCopy the code

Uni – app bluetooth:

// Code // Initial Bluetooth module this.pDeviceInfo = uni.getStoragesync ('deviceInfo'); if(!! this.pDeviceInfo){ this.prevConnected = true; } initBluetoothModule(){// The initial Bluetooth module uni.openBluetoothAdapter({success:res=> {this.searchbluelist (); }, fail:err=>{ console.log(err) } }) }, SearchBlueList () {/ / open bluetooth search uni. StartBluetoothDevicesDiscovery ({success: res = > {setTimeout (() = > {enclosing getBlueList (); Uni.showtoast ({title: 'open successfully ', icon: 'success', duration: 1000}); }, 1000); },})}, getBlueList(){// Get the search list uni.getbluetoothDevices ({success:res=> {let data = res.devices let tempList=[]; data.map(device=>{ if(!! device.localName){ tempList.push(device) } }); this.deviceNum = tempList.length; this.deviceList=tempList; this.listenBluetooth(); }}); }, listenBluetooth(){ let tempList =this.deviceList; / / to monitor bluetooth search uni. OnBluetoothDeviceFound ((res) = > {let flag = false; res.devices.forEach(device => { if(!! device.localName){ tempList.push(device) flag =true; } }) if(flag){ this.deviceList=tempList; this.deviceNum = this.deviceList.length; }})},Copy the code
connetBlue(type,index){ let deviceIndex = index; let deviceInfo = this.deviceList[deviceIndex]; if(this.prevConnected && type == 1){ deviceInfo = this.pDeviceInfo; } let dId = deviceInfo.deviceId; Uni. showLoading({title: 'Connecting... ', // the contents of the prompt, mask: true}); Uni.createbleconnection ({deviceId: dId,// deviceId success: res=> {uni.hideloading (); if(res.errCode == 0){ this.connected = true; this.connectedName=deviceInfo.name; uni.setStorageSync('deviceInfo',deviceInfo); this.deviceId=dId; Uni.showtoast ({title: 'connect successfully ', icon: 'success', duration: 1000}); } uni. StopBluetoothDevicesDiscovery ({success: res = > {the console. The log (' connection bluetooth after successful closed bluetooth search '); }})}, fail:err=>{uni. ShowToast ({title: 'Connection failed! ', icon: 'none', duration: 2000 }); }})}, getBLEDeviceServices(){// Get service uni.showloading ({title: 'printing... ', // the contents of the prompt, mask: true}); let deviceId = this.deviceId; uni.getBLEDeviceServices({ deviceId, success: (res) => { for (let i = 0; i < res.services.length; i++) { if (res.services[i].isPrimary) { this.getBLEDeviceCharacteristics(deviceId, res.services[i].uuid); } } }, fail: (res) => { uni.hideLoading(); Console. log(" Failed to obtain Bluetooth service: "+ JSON. Stringify (res)}})}, / / to get characteristic value of a single service (characteristic) getBLEDeviceCharacteristics (deviceId, serviceId) {if (!!!!! this.characteristics && !! this.serviceId){ this.PrintStr(); return; } uni.getBLEDeviceCharacteristics({ deviceId, serviceId, success: (res) => { uni.hideLoading(); for (let i = 0; i < res.characteristics.length; i++) { let item = res.characteristics[i]; if (item.properties.write && ! this.serviceId) { this.serviceId = serviceId; this.characteristics = item.uuid; this.PrintStr(); } } }, fail(res) { uni.hideLoading(); The console. The error (' failed to get characteristic value: 'res)}})}, closeBluetoothAdapter () {uni. CloseBluetoothAdapter ({success: Res => {console.log(' turn off bluetooth adapter '); }}); }, onUnload() { this.closeBluetoothAdapter(); }Copy the code

Go back to my previous articles and you may get more!

  • JS Sunflower treasure Book secret notes, escort for you gold three silver four
  • TypeScript learns early to become competitive in the workplace
  • A qualified junior front-end engineer needs to master module notes
  • More than 234.77 million words in front-end simulation interview
  • Vue.js pen test questions Solve common business problems
  • [Primary] Personally share notes of Vue front-end development tutorial
  • A long summary of JavaScript to consolidate the front end foundation
  • ES6 comprehensive summary
  • Dada front-end personal Web share 92 JavaScript interview questions with additional answers
  • [Illustrated, like collection oh!] Re-study to reinforce your Vuejs knowledge
  • 【 Mind Mapping 】 Front-end development – consolidate your JavaScript knowledge
  • 14 – even liver 7 nights, summed up the computer network knowledge point! (66 items in total)
  • This was my first JavaScript primer
  • LocalStorage and sessionStorage localStorage
  • Drag and drop in HTML5
  • Challenge the front-end HTTP/ECMAScript
  • Must learn must learn – Audio and video
  • 170 Interview questions + answer Learn to organize (conscience making)
  • Front-end HTML5 interviewers and candidates ask and answer questions
  • Ne Zha is sweeping the sea
  • Tencent location service development applications
  • [Advanced] The interviewer asked me how Chrome renders (6000 words)
  • The interviewer started by asking me about Chrome’s underlying principles and HTTP protocol (swastika)
  • Staying up late summed up the “HTML5 Canvas”
  • This /call/apply/bind
  • The HTTP/HTTPS/HTTP2 / DNS/TCP/classic problem
  • Execute context/scope chain/closure/first-class citizen
  • Web page creation basics
  • Learn the summary of HTML5 finger front-end (suggested collection, illustrated)

❤️ follow + like + Favorite + comment + forward ❤️

Likes, favorites and comments

I’m Jeskson, thanks for your talent: likes, favorites and comments, and we’ll see you next time! ☞ Thank you for learning with me.

See you next time!

This article is constantly updated. You can search “Programmer Doraemon” on wechat to read it for the first time, and reply [information] there are materials of first-line big factories prepared by me, which have been included in this article www.1024bibi.com

Star: github.com/webVueBlog/…

  • Hand in your homework technology creators, come here quickly! | creator camp phase ii