// function sortNumber(a,b)
// {
// return a - b
// }
//
// var arr = new Array(6)
// arr[0] = "10"
// arr[1] = "5"
// arr[2] = "40"
// arr[3] = "25"
// arr[4] = "1000"
// arr[5] = "1"
//
// document.write(arr + "<br />")
// document.write(arr.sort(sortNumber))
function NumberStack() {
this.stack = [21,2,60,4,5]; //栈的定义
}
NumberStack.prototype.push = function (num) {
if (typeof num != "number") return false;
this.stack.push(num);
};
NumberStack.prototype.pop = function () {
if(this.stack.length>0){
let last = this.stack.pop();
return last;
}
};
NumberStack.prototype.sys = function () {
return this.stack.indexOf(60)
};
NumberStack.prototype.max = function (n) {
this.stack.sort(this.sortfmax);
};
NumberStack.prototype.sortfmax =function sortNumber(a,b)
{
return a - b
}
NumberStack.prototype.base=function ()
{
return parseInt(500).toString(2);
}
var any=new NumberStack();
console.log(any.sys());
// var any=[1,2,3,4,5];
// any.pop();
// console.log(any)
// function Person(name,age,sex){
//
// this.name=name;
// this.age=age;
// this.sex=sex;
// this.sayName=function(){
// return this.name
// };
// }
//
// var per1=new Person("小王",18,"男");
// var per2=new Person("笑啥",18,"男");
// console.log(per1.sayName());//false
// console.log(per2.sayName());//false
// function Person(name,age,sex){
//
// this.name=name;
// this.age=age;
// this.sex=sex;
// this.sayName=fun;
// }
// function fun(){
// alert("this.name");
// };
//
// var per1=new Person("小王",18,"男");
// var per2=new Person("小李",28,"男");
//
// console.log(per1.sayName==per2.sayName)//tr
//
// function Person(name,age,sex){
//
// this.name=name;
// this.age=age;
// this.sex=sex;
// }
// //向原型中添加sayName方法
// Person.prototype.sayName=function(){
// return this.name
// };
// Person.prototype.bin=function () {
// console.log('举例')
// }
//
// var per1=new Person("小王",18,"男");
// var per2=new Person("小李",28,"男");
//
// per1.bin()
// console.log(per1.sayName())//true
// console.log(per2.sayName())//true
JavaScript基础算法:入栈与出栈 理解原型链
最新推荐文章于 2021-02-16 13:19:21 发布